static void MyMethod(ref MyClass f1, ref int f2)
		{
			f1.Val = f1.Val + 5;		// Add 5 to field of f1 param.
			f2	   = f2 + 5;			// Add 5 to second param.

			Console.WriteLine("f1.Val: {0}, f2: {1}", f1.Val, f2);
		}
		static void RefAsParameter(MyClass f1)
		{
			f1.Val = 50;
			Console.WriteLine("After member assignment: {0}", f1.Val);
			f1 = new MyClass();
			Console.WriteLine("After new object creation: {0}", f1.Val);
		}
        static void Main(string[] args)
        {
			MyClass a1 = new MyClass();
			
			Console.WriteLine("Before method call: {0}", a1.Val);
			RefAsParameter(a1);
			Console.WriteLine("After method call: {0}", a1.Val);
		}
        static void Main(string[] args)
        {
			MyClass a1 = new MyClass();
			int		a2 = 20;
			
			MyMethod(ref a1, ref a2);				// Call the method.
			Console.WriteLine("f1.Val: {0}, f2: {1}", a1.Val, a2);
		}
		static void RefAsParameter(ref MyClass f1)
		{
			// Assign to the object member.
			f1.Val = 50;
			Console.WriteLine("After member assignment: {0}", f1.Val);
			// Create a new object and assign it to the formal parameter.
			f1 = new MyClass();
			Console.WriteLine("After new object creation: {0}", f1.Val);
		}
        static void Main(string[] args)
        {
			MyClass mc = new MyClass();
			int someInt = 6;

			Console.WriteLine("Newsflash:	Sum: {0} and {1} is {2}", 5, someInt, mc.Sum(5, someInt));	// Invoke the method.

			Console.WriteLine("Newsflash:	Avg: {0} and {1} is {2}", 5, someInt, mc.Average(5, someInt));	// Invoke the method.
		}
Beispiel #7
0
        static void Main(string[] args)
        {
			MyClass mc = new MyClass();
			double volume, volume1;
			volume = mc.GetCylinderVolume(3.0, 4.0);
			volume1 = mc.GetCylinderVolume(radius:3.0, height:4.0);

			Console.WriteLine(volume);
			Console.WriteLine(volume1);
		}
        static void Main(string[] args)
        {
			MyClass mc = new MyClass();

			int r0 = mc.Calc(5, 6, 7);	// Use all explicit values.
			int r1 = mc.Calc(5, 6);		// Use default for c
			int r2 = mc.Calc(5);		// Use default for b, c
			int r3 = mc.Calc();			// Use all defaults

			Console.WriteLine("{0},{1},{2},{3}", r0, r1, r2, r3);
		}
Beispiel #9
0
        static void Main(string[] args)
        {
			MyClass mc = new MyClass();

			int r0 = mc.Calc(4, 3, 2);			// Positional Parameters
			int r1 = mc.Calc(4, b:3, c:2);		// Positional and Named Parameters
			int r2 = mc.Calc(4, c:2, b:3);		// Switch order
			int r3 = mc.Calc(c:2, b:3, a:4);	// All named parameters
			int r4 = mc.Calc(c:2, b:1+2, a:3+1);// Named parameter expressions

			Console.WriteLine("{0}, {1}, {2}, {3}, {4}", r0, r1, r2, r3, r4);
		}
Beispiel #10
0
        static void Main(string[] args)
        {
			int[] myArr = new int[] { 5, 6, 7 };	// Create and initialize array.
///			int first = 5, second = 6, third = 7;		// Declare three ints.
			MyClass mc = new MyClass();
///			mc.ListInts( first, second, third);			// Call the method.
///			Console.WriteLine("{0}, {1}, {2}", first, second, third);
			mc.ListInts(myArr);						// Call method to print the values.
			foreach (int x in myArr)
			{
				Console.WriteLine("{0}", x);		// Print out each element.
			}
			
		}
        static void Main(string[] args)
        {
			MyClass mc = new MyClass();
			double volume;

			volume = mc.GetCylinderVolume(3.0, 4.0);	// Positional.
			Console.WriteLine("Volume = " + volume);
			volume = mc.GetCylinderVolume(radius: 2.0);	// Use default height.
			Console.WriteLine("Volume = " + volume);
			volume = mc.GetCylinderVolume(height: 2.0);	// Use default radius.
			Console.WriteLine("Volume = " + volume);
			volume = mc.GetCylinderVolume();			// Use both default.
			Console.WriteLine("Volume = " + volume);
		}
Beispiel #12
0
		static void MyMethod(out MyClass f1, out int f2)
		{
			f1 = new MyClass();		// Create an object of the class.
			f1.Val = 25;			// Assign to the class field.
			f2     = 15;			// Assign to the int param.
		}