سلام بر تمامی برنامه نویسان سی شارپ 😉 در این پست آموزش linq: جدا کردن آیتم هایی که مقدار null دارند با where در سی شارپ را آماده کردم. انشاالله که این کد سی شارپ براتون مفید باشد.
کد linq: جدا کردن آیتم هایی که مقدار null دارند با where در سی شارپ :
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
class ProductWithNullablePrice
{
public string Name { get; private set; }
public decimal? Price { get; private set; }
public ProductWithNullablePrice(string name, decimal price)
{
Name = name;
Price = price;
}
ProductWithNullablePrice()
{
}
public static List<ProductWithNullablePrice> GetSampleProducts()
{
return new List<ProductWithNullablePrice>
{
new ProductWithNullablePrice { Name="C", Price= 9.99m },
new ProductWithNullablePrice { Name="A", Price= 4.99m },
new ProductWithNullablePrice { Name="F", Price= 3.99m },
new ProductWithNullablePrice { Name="S", Price=null}
};
}
public override string ToString()
{
return string.Format("{0}: {1}", Name, Price);
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
class ProductWithNullablePrice
{
public string Name { get; private set; }
public decimal? Price { get; private set; }
public ProductWithNullablePrice(string name, decimal price)
{
Name = name;
Price = price;
}
ProductWithNullablePrice()
{
}
public static List<ProductWithNullablePrice> GetSampleProducts()
{
return new List<ProductWithNullablePrice>
{
new ProductWithNullablePrice { Name="C", Price= 9.99m },
new ProductWithNullablePrice { Name="A", Price= 4.99m },
new ProductWithNullablePrice { Name="F", Price= 3.99m },
new ProductWithNullablePrice { Name="S", Price=null}
};
}
public override string ToString()
{
return string.Format("{0}: {1}", Name, Price);