value其实就是C#类里边的属性,比如,我们有个类叫Student,cs,里边有int类型名为“ID”的属性,我们在构造函数里接收传入的值然后为这个属性赋值,然后实例化类,传入一个1,这是value就是1;如下:

public class Student
    {
        public Student(int id)
        {
            this.Id = id;
        }
        public int Id
        {
            get { return Id; }
            set
            {
                if (value == 1)
                {
                    Console.WriteLine("hello world!");
                }
            }
        }
    }

然后实例化类,传入参数值,如下:

Student student = new Student(1);

Console.ReadKey();

这个时候就会输出:hello world!

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-01-14
  • 2021-04-22
猜你喜欢
  • 2021-06-04
  • 2022-02-06
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案