zoukankan      html  css  js  c++  java
  • 15、其他类

    一、Object类

      Object是所有类的基类。

      Object类中的方法 

      

    二、类包含

      包含类型是在另一个对象中作数据成员的对象类型。

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    
    namespace ConsoleApplication1
    {
        public class A
        {
            private string val1;   //声明了一个私有变量
            public A(string str)  //定制了一个构造函数
            {
                val1 = str;
            }
            public string Val1  //定义一个属性
            {
                get { return val1; }
                set { val1 = value; }
            }
        }
    public class B
        {
            private A bval1;
            public A Bval1
            {
                get { return bval1; }
                set { bval1 = value; }
            }
            public A Geta()
            {
                return new A("测试字符串");
            }
        }
        class Program
        {
            static void Main(string[] args)
            {
                B b = new B();
                b.Bval1 = new A("参数");
                Console.WriteLine(b.Bval1.Val1);
    
                A a = b.Geta();
                Console.WriteLine(a.Val1);
                Console.ReadLine();
            }
        }
    }

    三、类嵌套

      一个类完整的包含了另一个类。

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    
    namespace ConsoleApplication1
    {
                public class comp
        {
            public string name
                {
                get;
                set;           
                }
            public class cod
            {
                public string use;
                public cod(string name)
                {
                    use = name;
                }
                public string Use
                {
                    get
                    { return use; }
                    set
                    { use = value; }
                }
                public string codf(string name)
                {
                    return "我现在用的是" + name;
                }
                public static string aa(int i)
                {
                    return "一共有" + i + "语言";
                }
            }
            
        }
        class Program
        {
            static void Main(string[] args)
            {
                comp.cod cc = new comp.cod("电脑名称");
                Console.WriteLine(cc.use);
                Console.WriteLine(cc.codf("C#"));
                Console.WriteLine(comp.cod.aa(3));
                Console.ReadLine();      
            }
        }
        
    }

    四、匿名类型

      

    var Worker = new { name = "YWJ", age = 30, sex = "" };
                string str=Worker.name;
                int i = Worker.age;
                string str1 = Worker.sex;

    五、分部类

      

    六、扩展方法

  • 相关阅读:
    for 循环、序列和range()
    Python 中的 / 运算符的一切运算结果都是浮点数
    web如何测试
    性能测试中会遇到的瓶颈
    APP测试之内存命令查询
    接口测试常见的题目
    接口测试基础知识
    异或和之和 异或问题
    DP?
    Matrix Power Series
  • 原文地址:https://www.cnblogs.com/zytr/p/14737211.html
Copyright © 2011-2022 走看看