|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
|
|
Ajax Application Generator Generate database and reporting .NET Web apps in minutes. Quickly create visually stunning, feature-rich apps that are easy to customize and ready to deploy. Download Now!
|
|
#1
|
|||
|
|||
|
Article Wish List on Beginning C#
Hi,
I just started to learn the C#. I would like to have certain article talking about the basic things, like the ALL STRUCTURE of the C# functions and the basic use of them, etc. For example: static void Main() versus static void Main(string[] args) static int Main () versus static int Main (string[] args) static int functionname(int[] intArray) the use of public and private Since there is a static, do we have something called dynamic void()Main? Why we use static? Why we have "string[] args", etc. If there is an tutorial or article talking about this on the Internet, could you please provide the url.
__________________
Regrads, ckchin |
|
#2
|
|||
|
|||
|
hi ckchin,
i can help you out with all of that... first off: the difference between static void Main() and static void Main(string[] args) is that the arguement to main can be used to pass in words from the command line, so if we create a C# console app called blah.exe and i called it like this: blah.exe test1 test2 test3 then the args[] array in main would have three indexes which contained the string values "test1", "test2", and "test3". it's good for setting config options. static int Main () versus static int Main (string[] args) the int part is the return type of the function, so you'd have int Blah() { return 0; } to return an integer, or void Blah() { } so you don't have to return anthing from the function. in C#, all functions are encapsulated by a class. the static keyword means that you can call the function directly through the class and dont have to instantiate the class before hand, for example this would work: class myClass { static void blah() {} static void Main() { blah(); } } this code would also work: class myClass { function Blah() { } } class appClass { static void Main() { myClass mc = new myClass(); myClass.Blah(); } } the following code wouldnt work however class myClass { function Blah() { } } class appClass { static void Main() { myClass.Blah(); } } the code above doesnt work because the Blah() fnuction of myClass isn't static, meaning that its class must be instantiated (a new copy created) before it can be used... there's no equivelant dynamic function, you simply don't include static at the front of the function name. As for public, private, protected, abstract, etc they are access modifiers and you can use them to set the inheritance and access levels for functions. for example, class myClass { private void Blah(); } now if i derived a class from myClass, Blah() wouldn;t be accessible because it's private to the myClass function: // This code wouldnt work class myClass1 : myClass { } myClass1 mc1 = new myClass1(); // Error here mc1.Blah(); That's the general gist of things..syntax might be a bit out but you get the idea. here's some articles you might like to read: http://www.softsteel.co.uk/tutorial...p/lesson11.html http://www.pune-csharp.com/downloads/index.htm |
|
#3
|
|||
|
|||
|
Expanding on that,
when you define a method as static you are defining it as static cuz you know that there will only be one instance of that class thru out that application. eg. this class has 2 methods one is static and one is not class A { static void staticMethod() {} void normalMethod() {} } ok say you wanna use staticMethod. then you would do it like folowing A.staticMethod(); if you wanna use nomalmethod then you would do it liek A aInstance = new A(); aInstance.normalMethod(); This is really a feature of object oriented programming which isn't just about static and non static etc.. If you are willing to learn about this. There are books which just teaches you oop. eg this topic and more.including inhertence. Some of those books also have "WHEN" you can use these techniques and features which is most valuable if you are inexperienced programmer... hope this helped
__________________
Regards, James Yang .NET Developer / Network Engineer MCSE, MCDBA, MCSA, CCNA http://www.yellowpin.com/ http://www.opentechsupport.com/ |
|
#4
|
|||
|
|||
|
Thanks. I would like to make sure the followings are correct.
1) none (no modifier) can be used to instantiated using ... new, 2) static is only class-based accessible 3) abstract cannot be instantiated using new, and must be overriden 4) extern ... what is this? 5) virtual ... On NO what is this again? 6) new ... another what is this, example? I did read the C# beginning on the OOP chapter. This book only give example (very NOT clear examples) and did not listed down all the modifier and the use of them. Actually I did have a list of questions, and would like to ask here. BUT, I will make sure I finished reading the tutorial from the http://www.pune-csharp.com/downloads/index.htm (It is a great tutorial, and Thanks to Mytch because you share this url to me), and make a clear view of OOP (at least the basic one in C#) before the list of question here. |
![]() |
| Viewing: Dev Articles Community Forums > Programming > General Programming Help > Article Wish List on Beginning C# |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|