Buy Questpond's video subscriptions on
huge discount
.
Online: 4097
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
|
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 : 15869 | 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
How to get the exact property name while getting error
(0)
PDB file is not showing Line Number in dot net application hosted on server
(0)
Both Strings morethan 5 letters in length end of the words one vowel and one consonent is different
(0)
how to check Any adjacent letters transposed between two strings(ex: JOHN, JHON)
(1)
can't receive data after success login ?
(1)
Implement Multi-Tenant in Azure Logic Apps
(0)
Why ASP.Net Core 7.0 Web API showing as Connection refused?
(0)
Iterating over columns of dataframe and print as rows in Python Django
(0)
More ...