Often you need the data to remain unchanged from its reference point. |
using System; //method_ref.cs namespace key_ref_method { public class player { public static void info(ref int n, ref int score) { n = 10; score = 2; Console.WriteLine(n * score); } } class test { public static void Main() { int i = 0, j =0; // variable need be initialized //Static member cannot be accessed with an instance reference; //qualify it with a type name instead player.info(ref i, ref j); } } } |
using System; //method_ref_c.cs namespace key_ref_method { public class player { public static void info(ref int n, ref int score, ref string name) { n = 10; score = 2; name = "baba"; //Console.WriteLine(n * score + name); } } class test { public static void Main() { int i = 0, j =0; string s= "Jacob"; // variable need be initialized //Static member cannot be accessed with an instance reference; //qualify it with a type name instead //note the ref points are not changed player.info(ref i, ref j, ref s); Console.WriteLine(i * j + s); } } } |