C#属性默认值设置(model实体类)

关于在MVC中view中设置默认值,可以象如下设置:

1、关于VIEWMODEL的部分

如果是C#  6.0, 

public class Test{
 
public int X { get; set; } = 100;
 
public string Y { get; set; } = "test";
 
}

如果语法不支持,只能改回.net 2.0的写法。

 
public class UserType
    {
        private int _UserType = 1;
        public int UserTypeID 
        {
            get
            {
                return this._UserType;
            }
            set
            {
                this._UserType = value;
            }
        }
    }

转: https://blog.csdn.net/qq_39569480/article/details/104651722

原文地址:https://www.cnblogs.com/fps2tao/p/14707644.html