Library tutorials & articles
Program Entry point in C#
- Introduction
- Example 1 & 2
- Example 3 & 4
- More Examples
- Additional Examples
Additional Examples
kamran.cs
public static void Main() {
System.Console.WriteLine("hell");
}
class zzz
{
}
Compiler Error
kamran.cs(1,15): error CS1518: Expected class, delegate, enum,
interface, or struct
You cannot create a function outside a class or a structure. This rule has to
be strictly adhered to even for Main.
kamran.cspublic class zzz
{
public
static int Main()
{
return;
}
}
Compiler Errorkamran.cs(5,1): error CS0126: An object of a type convertible
to 'int' is required
In this example, the function Main has to return an int and we are not returning
any value with the keyword return. The compiler tries to convert a nothing into
an int and hence the error. This is a generic error that occurs whenever the
compiler tries to convert a data type into another and is not successful.
kamran.csclass zzz
{
public
static int Main()
{
}
}
Compiler Errorkamran.cs(3,19): error CS0161: 'zzz.Main()': not all code paths
return a value
The compiler's error messages need the services of an editor. The function Main should return an int, but we forgot to do so. This results in an error. Thus whenever an entity should return a value, we should return such a data type or be prepared for an error.
Happy .NETing
Related articles
Related discussion
-
C# video Editing/rendering
by pkuchaliya (0 replies)
-
How to Fill DataSet with more records (around 1 lakh) in a faster way
by Jayaram P (0 replies)
-
Can't print on the network with MSADESS ??
by anatha1 (2 replies)
-
Very Urgent regarding deleting the images from a folder
by Nanosteps (6 replies)
-
DataGridViewComboBoxColumn not showing values
by sachinkalse (0 replies)
Related podcasts
-
Object-Oriented Programming in Ruby
In this episode, I talk with Scott Bellware about object-oriented programming in Ruby, and Ruby's object model. This is taken from a private conversation, and the audio quality suffers at times. Much thanks to Scott for allowing this to be released.This episode of the Alt.NET Podcast is bro...
I am not discouraging you, but I just dont see a need for an article on this issue. One can find out those errors on trial and error basis with a test program. Give us something new and creative!
This thread is for discussions of Program Entry point in C# .