C# variables, methods, reference exercise -


i have made exercise on c#, here is:

class program {     static double funk(int a, ref int b)     {         double c = + b;         = 5;         b = * 3;         return c;     }  static void main(string[] args) {     int = 1, b = 2;     console.writeline(funk(a, ref b));     console.writeline(a);     console.writeline(b);     console.readline(); } 

so, result pretty clear when run code, gives me:

3 1 15 

my question is, did 15 , 3 came from?

the 3 came from:

double c = + b;  //... return c; 

this gets printed out console via first writeline.

the 15 comes from:

double c = + b; // c == 3 = 5; b = * 3; // b == 5 * 3 == 15 

since pass in b ref, you're changing actual value of caller variable (b in main), gets set 15, printed out third writeline.


Comments

Popular posts from this blog

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -