ASP.NET中基本语言特性
2024-08-26 22:46:33
- 自动属性
public string Name { get; set; }
- 对象与集合的初始化
//自动推断类型//集合的初始化
var Products=new List<Product>{
new Product{Name="苹果",Price=4.5M,CategoryNumber=},
new Product{Name="橘子",Price=2.5M,CategoryNumber=},
new Product{Name="柚子",Price=4.5M,CategoryNumber=},
new Product{Name="西红柿",Price=3.0M,CategoryNumber=},
new Product{Name="茄子",Price=1.5M,CategoryNumber=}
};
//自动推断类型//对象的初始化
var product = new Product
{
Name = "苹果",
Price = 3.7m,
CategoryNumber =
}; - 扩展方法
1、对接口运用扩展方法
2、创建过滤扩展方法 - 使用lambda表达式
k => k.Price
- 使用自动类型接口
class Program
{
static void Main(string[] args)
{
//自动推断类型
var product = new Product
{
Name = "苹果",
Price = 3.7m,
CategoryNumber =
};
Console.WriteLine(product.CategoryNumber);
}
public class Product
{
public string Name { get; set; }
public decimal Price { get; set; }
public int CategoryNumber { get; set; }
}
} - 使用匿名类型
var Category = new
{
CategoryNumber = ,
CategoryName = "食品"
}; - 执行语言集成查询(LINQ)
var Products=new List<Product>{
new Product{Name="苹果",Price=4.5M,CategoryNumber=},
new Product{Name="橘子",Price=2.5M,CategoryNumber=},
new Product{Name="柚子",Price=4.5M,CategoryNumber=},
new Product{Name="西红柿",Price=3.0M,CategoryNumber=},
new Product{Name="茄子",Price=1.5M,CategoryNumber=}
};
//linq 查询1(查询语法)
var pro1 = from t in Products
orderby t.Price descending
select new { t.Name, t.Price };
//linq 查询2(点语法/链式语法)
var pro2 = Products.OrderByDescending(k => k.Price).Take().Select(k => new { k.Name, k.Price }); - 使用Async方法
运用async和await关键字 - 使用委托
//委托方法
Func<Product, bool> fun = delegate(Product n)
{
return n.Price > ;
};
var pro3 = Products.OrderByDescending(fun);
//或者(委托简写)
var pro4 = Products.OrderByDescending(k=>k.Price>);
最新文章
- select初始化添加option,通过标签给出回显值,由于回显值和初始化值option中有一个值重复,去重等问题!
- 将excel文件批量转成pdf
- MVVM架构~前台后台分离的思想与实践
- poj1637 Sightseeing tour
- IOS启动顺序
- Windows 7下安装MongoDB
- C语言的变量的内存分配
- C++11 作用域内枚举
- 根据hash值找到bt种子的磁力下载链
- mybatis的typeHandler
- pyspider爬取数据存入redis--2.测试数据库连通性
- eventql部署过程
- drupal7 hook_validate
- 在虚拟机下安装Ubuntu
- Oracle查询优化-插入、更新与删除
- Web安全之CSRF攻击的防御措施
- Sheldon Numbers GYM -- 枚举
- [JZOJ5426]摘Galo
- php解析二维码
- ZOJ18th省赛 Lucky 7