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

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM