0

What's the most important function in c#

8th Nov 2016, 6:46 PM
Axel
Axel - avatar
3 Antworten
+ 3
Every C# application must contain a single Main method specifying where program execution is to begin. In C#, Main is capitalized, while Java uses lowercase main. Main can only return int or void, and has an optional string array argument to represent command-line parameters: static int Main(string[] args) { //... return 0; } Specify this keyword on a value type parameter when you want the called method to permanently change the value of variables used as parameters. This way, rather than passing the value of a variable used in the call, a reference to the variable itself is passed. The method then works on the reference, so that changes to the parameter during the method's execution are persisted to the original variable used as a parameter to the method. The following code illustrates this in the Add method, where the second int parameter is passed by reference with the ref keyword: class TestRef { private static void Add(int i, ref int result) { result += i; return; } static void Main() { int total = 20; System.Console.WriteLine("Original value of 'total': {0}", total); Add(10, ref total); System.Console.WriteLine("Value after calling Add(): {0}", total); } } The out keyword has a very similar effect to the ref keyword, and modifications made to a parameter declared using out will be visible outside the method. The two differences from ref are that any initial value of an out parameter is ignored within the method, and secondly that an out parameter must be assigned to during the method: class TestOut { private static void Add(int i, int j, out int result) { // The following line would cause a compile error: // System.Console.WriteLine("Initial value inside method: {0}", result); result = i + j; return; } static void Main() { int total = 20; System.Console.WriteLine("Original value of 'total': {0}", t
8th Nov 2016, 7:52 PM
Abdelaziz Abubaker
Abdelaziz Abubaker - avatar
+ 1
The most important about functions is that you can to make your own! Also I like the answer TechTro gave. should've made some things clear for you
9th Nov 2016, 12:42 AM
Machiel
0
thank you
11th Nov 2016, 5:17 PM
Axel
Axel - avatar