• 类的属性成员


    假定学校要统计学生的信息,包括学生姓名,学号和所在系等。要求把这些学生信息设置成学生类的属性,并通过属性访问函数来设置和读取这些信息

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;

    namespace leideshuxingchengyuan
    {
    public class Student
    {
    private long id;
    public static int a;
    public long Id//定义属性以访问私有字段id.
    {
    get { return id; }//定义属性以访问私有字段id,并返回一个值存放在testnumber中
    set { id = value; }
    }
    private string name;
    public string Name
    {
    get { return name; }
    set { name = value; }
    }
    private static string departmentName;
    public static string DepartmentName
    {
    get { return departmentName; }
    set { departmentName = value; }
    }
    public Student(long id, string name)
    {
    this.id = id;
    this.name = name;
    }
    public long testnumber
    {
    get
    {
    return (id * 3 - 1000);
    }
    }
    }
    class Program
    {
    static void Main(string[] args)
    {
    Student.DepartmentName = "计算机学院";//静态属性赋值。
    Student student = new Student(12000,"张三");
    Student.a = 3;
    Console.WriteLine("学生一:学号={0},姓名={1},准考证={2},所在院系={3},{4}",student.Id,student.Name,student.testnumber,Student.DepartmentName,Student.a);
    Student.a += 4;
    Student student1 = new Student(12001, "李四");
    Console.WriteLine("学生二:学号={0},姓名={1},准考证={2},所在院系={3},{4}", student1.Id, student1.Name, student1.testnumber, Student.DepartmentName,Student.a);
    }
    }
    }

  • 相关阅读:
    var与dynamic
    SQL Server占用服务器内存过高
    SQL SERVER 2012/ 2014 分页,用 OFFSET,FETCH NEXT改写ROW_NUMBER的用法
    SQL Server 2012 OFFSET/FETCH NEXT分页示例
    Solr初始化源码分析-Solr初始化与启动
    (c#) 销毁资源和释放内存
    C#中 ThreadStart和ParameterizedThreadStart区别
    MongoDB的C#封装类
    mongo DB for C#
    C#操作MongoDB
  • 原文地址:https://www.cnblogs.com/yinyitianya/p/5678006.html
Copyright © 2020-2023  润新知