using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Linq
{
public class Product
{
private string name;
private int price;
public Product(int _price, string _name)
{
Name = _name;
Price = _price;
}
public string Name
{
get
{
return name;
}
set
{
name = value;
}
}
public int Price
{
get
{
return price;
}
set
{
price = value;
}
}
}
delegate int TwoNums(int x, int y);
class Program
{
static void Opera(TwoNums twoNums)
{
for (int x = 1; x <= 5; x++)
{
for (int y = 1; y <= 5; y++)
{
int Result = twoNums(x,y);
Console.WriteLine("({0},{1})={2}",x,y,Result);
if (y != 5)
{
Console.WriteLine(",");
}
}
Console.WriteLine(",");
}
}
static void Main(string[] args)
{
#region
//List<Product> product = new List<Product>();
//product.Add(new Product(10, "name1"));
//product.Add(new Product(500, "name2"));
//product.Add(new Product(72, "name5"));
//product.Add(new Product(9, "name4"));
//// List<Product> cheapest = product.FindAll(delegate (Product p) { return p.Price < 25 || p.Name.Contains("5"); });
//List<Product> cheapest = product.FindAll(p => p.Price == 500 || p.Name.Contains("5"));
//// 因为sort 方法是 void 类型 所以 直接执行后 product发生改变
//// 降序:
////lstroot.Sort((x, y) => y.static_count.CompareTo(x.static_count));
//// 升序:
////lstroot.Sort((x, y) => x.static_count.CompareTo(y.static_count));
//product.Sort((x, y) => x.Price.CompareTo(y.Price));
//foreach (var ss in cheapest)
//{
// Console.WriteLine(ss.Name+":"+ss.Price);
//}
//Console.ReadKey();
#endregion
Opera((x, y) => x + y);
Opera((x, y) => x - y);
Opera((x, y) => x * y);
Opera((x, y) => x / y);
Console.ReadLine();
}
}
}
Expression lambda simple utilisant le délégué pour réaliser l'addition, la soustraction, la multiplication et la division en 5
Je suppose que tu aimes
Origine blog.csdn.net/qq_38992403/article/details/105437763
conseillé
Classement