EF笔记
1.自动属性:
public class Person { public int Id { get; set; } public string Name { get; set; } }
2.隐式类型:
编译器会根据赋值变量自动判断隐式类型的类型,类型确定后不可以更改,变量声明需要初始化,且不能为null,只能是局部变量。
3.对象初始化器和集合初始化器:
Person p1 = new Person{ Id = 1 ,Name="zs"}; Person[] p2 = new Person[] { new Person { Id = 1, Name = "zs" }, new Person { Id = 2, Name = "ww" } };
4.匿名类:
var p = new { name = "小呆", age = 12 };
5.扩展方法:
public static class Extensions { public static bool IsVaildEmailAddress(this string s) { Regex regex =new Regex(@"^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$"); return regex.IsMatch(s); } } static void Main(string[] args) { string email = "www.45642@163.com"; if (!email.IsVaildEmailAddress()) { Console.WriteLine("不符合邮件地址标准!"); } }