惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
腾讯CDC
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
L
LINUX DO - 热门话题
D
Darknet – Hacking Tools, Hacker News & Cyber Security
Project Zero
Project Zero
V
Vulnerabilities – Threatpost
Cisco Talos Blog
Cisco Talos Blog
P
Palo Alto Networks Blog
C
Cisco Blogs
A
Arctic Wolf
月光博客
月光博客
The GitHub Blog
The GitHub Blog
T
The Blog of Author Tim Ferriss
量子位
小众软件
小众软件
Latest news
Latest news
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Microsoft Security Blog
Microsoft Security Blog
T
The Exploit Database - CXSecurity.com
Security Latest
Security Latest
N
Netflix TechBlog - Medium
K
Kaspersky official blog
人人都是产品经理
人人都是产品经理
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
博客园_首页
Y
Y Combinator Blog
P
Proofpoint News Feed
H
Hackread – Cybersecurity News, Data Breaches, AI and More
M
MIT News - Artificial intelligence
T
Threat Research - Cisco Blogs
S
Schneier on Security
D
Docker
Scott Helme
Scott Helme
MyScale Blog
MyScale Blog
Spread Privacy
Spread Privacy
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
GbyAI
GbyAI
有赞技术团队
有赞技术团队
Google DeepMind News
Google DeepMind News
The Hacker News
The Hacker News
H
Help Net Security
Simon Willison's Weblog
Simon Willison's Weblog
J
Java Code Geeks
C
Cyber Attacks, Cyber Crime and Cyber Security
T
Tenable Blog
B
Blog
Know Your Adversary
Know Your Adversary
IT之家
IT之家

博客园 - 赶路人之刚出发

集成WebSecurity的Authorize进行身份验证时,数据库连接报错问题 Html.ActionLink传递参数 Automapper结合EF实现insert,update方法 MVC中使用RemoteAttribute异步远程验证 Html.RenderPartial WebMatrix.WebSecurity创建自定义用户属性 强类型view中List<Model〉问题 ViewBag任意属性的实现方法 params关键字 配置LINQ中的datacontext的log路径,以记录datacontext执行了的查询sql SortedList LINQ join/left join/cross join/group by/group join/sortedlist/cast Linq to objects示例 yield return 和 Func Lamda表达式 IDisposable 匿名类型与扩展方法 C#自动属性 .net random伪随机数
对象初始化器和集合初始化器
赶路人之刚出发 · 2013-04-11 · via 博客园 - 赶路人之刚出发

对象初始化器和集合初始化器,类似自动属性,一种省事的写法,参见下例绿色部分:

1 namespace Demo
 2 {
 3     class Program
 4     {
 5         static void Main(string[] args)
 6         {
 7             //以前我们可能这么写
 8             //对象
 9             Person p1 = new Person();
10             p1.Name = "Joey";
11             p1.Age = 25;
12             //集合
13             List<Person> ps1 = new List<Person>();
14             Person joey = new Person();
15             joey.Name = "joey";
16             joey.Age = 25;
17             Person zhangSan = new Person();
18             zhangSan.Name = "ZhangSan";
19             zhangSan.Age = 18;
20             //然后加入集合
21             ps1.Add(joey);
22             ps1.Add(zhangSan);
23             //数组
24             int[] a1 = new int[3];
25             a1[0] = 1;
26             a1[1] = 2;
27             a1[2] = 3;
28 
29             //有了初始化器后 我们可以这么写
30             //对象
31             var p2 = new Person { Name = "Joey", Age = 25 };
32 
33             //集合
34             var ps2 = new List<Person> { 
35                 new Person{ Name="Joey", Age=25 },
36                 new Person{Name="ZhangSan", Age=18 }
37             };
38             //数组
39             var a2 = new int[] { 1, 2, 3 };
40         }
41     }
42 
43     public class Person
44     {
45         public int ID { get; private set; }
46 
47         public string Name { get; set; }
48         public int Age { get; set; }
49 
50     }
51 }