C# No.3

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();
}
}
}

转载于:https://www.cnblogs.com/yi-jie/p/4378811.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值