Download
100% FREE
Office Document APIs for .NET
Online: 1270
Home
Articles
Interviews
Forums
For Beginners
Popular Questions
ITIL Career Advice
PMP Career Advice
Career Advices
Codes
Videos
ASP.NET
ASP.NET MVC
Android Intel XDK
Sql Server
AngularJS
Bootstrap
Backbone.JS
MongoDB
LESS (CSS)
jQuery
WPF
WWF
SSIS
LightSwitch
Tutorials
News
ASP.NET MVC
|
Be Interview Ready
|
Top Performers
|
DNF MVP
|
Top Posts
|
Winners
|
Subscribe
|
Bookmarks
|
Catalogs
Welcome Guest !
Register
Login
Home
>
Forums
>
C#
>
Loading ...
Why main is static in C# ? [Resolved]
Posted by
Akiii
under
C#
on 9/22/2011 |
Points: 10
| Views : 13532 | Status :
[Member]
| Replies : 3
Write New Post
|
Search Forums
|
Resolved Posts
|
Un Answered Posts
|
Forums Home
Hi folks,
Can anyone please tell me with an example, why main is static in C# ?
Thanks and Regards
Akiii
[Resolved]
Reply
|
Reply with Attachment
Alert Moderator
Responses
Posted by:
Shiv007
on: 9/23/2011
[Member]
Starter
|
Points: 50
0
Static methods are the methods which do not require any object whenever they are called. These methods are loaded even before the class is loaded in the memory.. It means that even before the object is being created .. the method is already loaded into the memory.... Other than this, Main() is the door for any program..... It means whenever you run a program, the compiler looks out for the Main method.... If there is a main method then the content onside it is executed.... The main method is the first access point for any program and has to be called automatically.. Since it is static it gets loaded automatically even before the object of that class is being created and... Main() does not require any object to be called!!!!
class MyClass
{
public void myDetails()
{ Console.WriteLine("Hello World"); }
public static void Main()
{
MyClass m = new MyClass();
m.myDetails();
}
}
See in this example, i have created a non-static method which requires an object to be called. The method gets loaded into the memory when the complier
executes the line m.myDetails(); Main method is static and does not requires an object to be created to call it.....Hence it is static and the other reason is that it is the entry point for any program..... Neways this much is what i have got to tell you!!!
Hope this much information is OK... If get confused then please post your query..
Akiii
, if this helps please
login
to
Mark As Answer
. |
Alert Moderator
Posted by:
Rickeybglr
on: 9/23/2011
[Member]
Starter
|
Points: 25
0
http://msdn.microsoft.com/en-us/library/79b3xss3.aspx
Akiii
, if this helps please
login
to
Mark As Answer
. |
Alert Moderator
Posted by:
Akiii
on: 9/24/2011
[Member]
Bronze
|
Points: 25
0
@rickey....
thanks for the link..
@Shivanand...
its a nice explanation.......thanks for your answer...
But please do post your code in code tags, it will look elegant....
Regards
Akiii
Akiii
, if this helps please
login
to
Mark As Answer
. |
Alert Moderator
Login to post response
Latest Posts
Error no value given for one or more required parameters.' select from excelsheet
(0)
New
display data in html table from json file
(1)
Display record from json file in mvc
(0)
how to know the return type of json object using LogFile in c#
(1)
Upload image having bigger size (20 MB or more) using canvas in HTML5
(1)
Download any file having more than 50 MB size using Javascript on IE
(0)
Congratulations to all monthly winners of Mar 2018
(1)
OST to PST Converter
(2)
More ...