以下代码展示了一个类型定义,其中包含了所有可能的成员。这段代码会通过编译(会显示一些警告),但它并不能代表你平常创建的类型,其中大多数方法没有实用价值。这里仅仅是为了列举出来而已,有遗漏的话 希望园友们提示一下,我会追加上。。

谢谢了。。

 

using System;

public sealed class SomeType                            //1
{
    //嵌套类
    private class SomeNestdType { }                     //2

    //常量、只读字段和静态可读/可写字段
    private const Int32 SomeConstant = 1;               //3
    private readonly Int32 SomeReadOnlyField = 2;       //4
    private static Int32 SomeReadWriteField = 3;        //5

    //类型构造器
    static SomeType() { }                               //6

    //实例构造器
    public SomeType(Int32 x) { }                        //7
    public SomeType() { }                               //8

    //实例方法和静态方法
    private string InstanceMethod() { return null; }    //9
    public static void Main() { }                       //10

    //实例属性
    public Int32 SomeProp                               //11
    {
        get { return 0; }                               //12
        set { }                                         //13
    }

    //实例有参属性(索引器)
    public Int32 this[string s]                         //14
    {
        get { return 0; }                               //15
        set { }                                         //16
    }

    public event EventHandler SomeEvent;                //17
}

 

参考:http://www.wxzzz.com/?id=96

 

相关文章:

  • 2022-02-14
  • 2021-06-03
  • 2022-12-23
  • 2022-12-23
  • 2021-06-03
  • 2022-02-24
  • 2022-12-23
猜你喜欢
  • 2021-05-28
  • 2021-05-19
  • 2021-05-17
  • 2021-10-23
  • 2022-12-23
  • 2021-05-21
  • 2022-12-23
相关资源
相似解决方案