标签:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace myclass
{
class mc
{
private
int testnum1;
int testnum2;
public mc(int i)
{
testnum1 = i;
testnum2 = 0;
}
public mc()
: this(5)
{
testnum2 = 7;
}
public void show()
{
Console.WriteLine("{0} {1}",testnum1,testnum2);
}
}
class test
{
static void Main()
{
mc a = new mc(20);
mc b = new mc();
a.show();
b.show();
}
}
}
Font anotherFont = new Font( "Courier", 12.0f );
using ( anotherFont )
{ // use anotherFont } // compiler calls Dispose on anotherFont
// using anotherFont here will fail
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication3
{
class Program
{
public static void getnum(int a,int b,int c)
{
a = 10;
b = 20;
c = 30;
}
static void Main(string[] args)
{
int a = 1;
int b = 2;
int c = 3;
getnum(a, b, c);
Console.WriteLine("{0} {1} {2}", a, b, c);
}
}
}
class Program
{
public static void getnum(ref int a,ref int b,ref int c) // ref
{
a = 10;
b = 20;
c = 30;
}
static void Main(string[] args)
{
int a = 1;
int b = 2;
int c = 3;
getnum(ref a,ref b,ref c); // ref
Console.WriteLine("{0} {1} {2}", a, b, c);
}
}
}
// out 可不赋初值
//ref 必须赋初值
// ref 和 out 可在同意函数中混合使用
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication4
{
public class A
{
public virtual void print()
{
Console.WriteLine("Parent Method");
}
}
public class B : A
{
public void child()
{
Console.WriteLine("Child Method");
}
public override void print()
{
Console.WriteLine("Overriding child method");
}
}
class Program
{
static void Main(string[] args)
{
A a = new A();
B b = new B();
a.print();
b.print();
}
}
}
标签:
原文地址:http://www.cnblogs.com/yi-jie/p/4378811.html