码迷,mamicode.com
首页 > Windows程序 > 详细

C# No.3

时间:2015-03-30 20:46:33      阅读:149      评论:0      收藏:0      [点我收藏+]

标签:

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

技术分享

C# No.3

标签:

原文地址:http://www.cnblogs.com/yi-jie/p/4378811.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!