zoukankan      html  css  js  c++  java
  • 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();
    }
    }
    }

  • 相关阅读:
    线程的五种状态
    ajax回调打开新窗体防止浏览器拦截有效方法
    mysql 如果字段为null自动返回需要的信息sql
    String 与 StringBuffer的区别
    Windows Git中文文件名乱码
    定义函数指针
    hello world
    C++析构函数调用异常问题研究
    企业开发的时候,有可能碰到的问题
    jmap
  • 原文地址:https://www.cnblogs.com/yi-jie/p/4378811.html
Copyright © 2011-2022 走看看