Ex1: class RefOutOverloadExample { public void SampleMethod(int i) { } public void SampleMethod(ref int i) { } } Ex2: class RefOutOverloadExample { public void SampleMethod(int i) { } public void SampleMethod(out int i) { } }
Passing Arrays Using ref and out void TestMethod1(out int[] arr) { arr = new int[10]; } void TestMethod2(ref int[] arr) { arr = new int[10]; }
class TestOut { void FillArray(out int[] arr) // Initialize the array: arr = new int[5] { 1, 2, 3, 4, 5 }; } static void Main() { TestOut ob=new TestOut(); int[] theArray; // Initialization is not required ob. FillArray(out theArray); // Pass the array to the callee using out: // Display the array elements: System.Console.WriteLine("Array elements are:"); for (int i = 0; i < theArray.Length; i++) System.Console.Write(theArray[i] + " ");
The params Keyword using System; namespace UsingParams { public class Tester public void DisplayVals(params int[] y) foreach (int i in y) Console.WriteLine("The Value {0}",i); } static void Main( ) Tester t = new Tester( ); t.DisplayVals(5,6,7,8); int [] x = new int[5] {1,2,3,4,5}; t.DisplayVals(x);
Object using System; namespace boxing { public class UnboxingTest { public static void Main( ) { int i = 123; object o = i; //Boxing int j = ( int ) o; // unboxing (must be explicit) Console.WriteLine( "j: {0}", j ); }
using System; class xxx { public int i = 10; } class MainClass static void Main() object a; a = 1; // an example of boxing Console.WriteLine(a); a = new xxx(); xxx b; b = (xxx)a; Console.WriteLine(b.i);
public class MyClass { public void UseParams(params int[] list) for (int i = 0 ; i < list.Length; i++) Console.WriteLine(list[i]); } Console.WriteLine(); public void UseParams2(params object[] list) static void Main() MyClass ob= new MyClass(); ob.UseParams(1, 2, 3); ob.UseParams2(1, 'a', "test"); int[] myarray = new int[3] {10,11,12}; ob.UseParams(myarray); }}
Enumerations <modifier> enum <enumeration name> { - - - - - - - - - - - - - - - };