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

推荐订阅源

S
Schneier on Security
有赞技术团队
有赞技术团队
T
The Blog of Author Tim Ferriss
F
Fortinet All Blogs
D
DataBreaches.Net
F
Full Disclosure
腾讯CDC
博客园 - 【当耐特】
MyScale Blog
MyScale Blog
Stack Overflow Blog
Stack Overflow Blog
小众软件
小众软件
Hugging Face - Blog
Hugging Face - Blog
Last Week in AI
Last Week in AI
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
爱范儿
爱范儿
The GitHub Blog
The GitHub Blog
Engineering at Meta
Engineering at Meta
大猫的无限游戏
大猫的无限游戏
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
S
SegmentFault 最新的问题
The Register - Security
The Register - Security
WordPress大学
WordPress大学
博客园 - 聂微东
雷峰网
雷峰网
J
Java Code Geeks
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
P
Privacy International News Feed
酷 壳 – CoolShell
酷 壳 – CoolShell
A
Arctic Wolf
Scott Helme
Scott Helme
C
Cyber Attacks, Cyber Crime and Cyber Security
T
Tor Project blog
博客园 - 三生石上(FineUI控件)
Know Your Adversary
Know Your Adversary
AWS News Blog
AWS News Blog
G
Google Developers Blog
www.infosecurity-magazine.com
www.infosecurity-magazine.com
C
CERT Recently Published Vulnerability Notes
O
OpenAI News
Project Zero
Project Zero
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
Application and Cybersecurity Blog
Application and Cybersecurity Blog
云风的 BLOG
云风的 BLOG
N
News and Events Feed by Topic
MongoDB | Blog
MongoDB | Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
Microsoft Security Blog
Microsoft Security Blog
Cisco Talos Blog
Cisco Talos Blog
P
Palo Alto Networks Blog
Schneier on Security
Schneier on Security

博客园 - 赶路人之刚出发

集成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 }