C# 6.0的属性(Property)的语法与初始值详解
- 作者: 段子就是本黄书
- 来源: 51数据库
- 2022-04-04
昨晚有学点新知识,是有关c# 6.0的。
在数据库创建有一张表:
create table [dbo].[toollocation] ( [toollocation_nbr] smallint identity(1,1) not null primary key, [locationname] nvarchar(20) not null, [description] nvarchar(50) null, [isactive] bit not null default(1) ) go source code
看看前后对比与写法:
using system; using system.collections.generic; using system.linq; using system.text; using system.threading.tasks; namespace insus.net.models { public class toollocation { public short toollocation_nbr { get; set; } = 1; public string locationname { get; set; } = string.empty; public string description { get; set; } = string.empty; public bool isactive { get; set; } = true; } } source code
下面insus.net演示一下,创建一个实体:
using insus.net.models; using system; using system.collections.generic; using system.linq; using system.text; using system.threading.tasks; namespace insus.net.entities { public class toollocationentity { public ienumerable<toollocation> toollocations() { return new list<toollocation>() { new toollocation(), new toollocation { toollocation_nbr = 2, locationname = "a2", description = "a2 cnc",isactive = true}, new toollocation { toollocation_nbr = 3, locationname = "c4", description = "c4 cnc",isactive = false} }; } } } source code
它将会有三个对象,第一个对象是使用默认值。
在控制器中:
在asp.net mvc视图中,显示这些数据:
看看运行的效果:
以上这篇c# 6.0的属性(property)的语法与初始值详解就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持。
推荐阅读
- C#通过fleck实现wss协议的WebSocket多人Web实时聊天(附源码)
- 团队城市未满足要求:MSBuildTools12.0_x86_Path 存在
- 使用 MSBuild.exe 在发布模式下构建 C# 解决方案
- 当我发布 Web 应用程序时,AfterPublish 脚本不运行
- 构建时 T4 转换的产品仅在下一个构建中使用
- ASP.NET Core Application (.NET Framework) for Windows x64 only error in project.assets.json
- 新的 .csproj 格式 - 如何将整个目录指定为“链接文件"到子目录?
- 如何将条件编译符号(DefineConstants)传递给 msbuild
- MSBuild 支持 Visual Studio 2017 RTM 中的 T4 模板
- NuGet 包还原找不到包,没有源
热点文章
团队城市未满足要求:MSBuildTools12.0_x86_Path 存在
0
使用 MSBuild.exe 在发布模式下构建 C# 解决方案
0
当我发布 Web 应用程序时,AfterPublish 脚本不运行
0
构建时 T4 转换的产品仅在下一个构建中使用
0
ASP.NET Core Application (.NET Framework) for Windows x64 only error in project.assets.json
0
新的 .csproj 格式 - 如何将整个目录指定为“链接文件"到子目录?
0
如何将条件编译符号(DefineConstants)传递给 msbuild
0
MSBuild 支持 Visual Studio 2017 RTM 中的 T4 模板
0
NuGet 包还原找不到包,没有源
0
使用 C# 6.0 功能运行 TFS 构建
0