设为首页 加入收藏

TOP

c#属性1(Property)
2019-09-18 11:10:07 】 浏览:24
Tags:属性 Property

创建一个只读属性

using System;
using System.Collections;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using 编码练习;

namespace 编码练习
{
    //创建类people,里面有两个属性
    public class Employee
    {
        public static int NumberOfEmployees;
        private static int counter;
        private string name;

        // A read-write instance property:
        public string Name
        {
            get { return name; }
            set { name = value; }
        }

        // A read-only static property:
        public static int Counter
        {
            get { return counter; }
        }

        // A Constructor:
        public Employee()
        {
            // Calculate the employee's number:
            counter = ++NumberOfEmployees;
        }
    }
}
public class SerchPeople
{
    public static void Main()
    {
        Employee.NumberOfEmployees = 107;
        Employee e1 = new Employee();
        e1.Name = "cave";
        Console.WriteLine(Employee.Counter);
    }
}
}

 

】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇protoc文件生成cs文件 下一篇c#索引器

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目