Code
var result = GetProducts();//list
var result1 = GetProductsArray();//array
var result2 = GetProductsDict();//dict
//list and array --> ILIST...
//dic --> Idiction..
//Ilist and Idic --> Icollection
Display(result);
Display(result1);
Display(result2.Values);
Console.WriteLine("test");
bool result12 = false;
System.Console.WriteLine(bool.TryParse("Off", out result12));
static void Display(ICollection products)
{
foreach (var item in products)
{
Console.WriteLine(item.Price);
}
}
/*IList...IDictionary,,Icollection....IEnumerable....
*
* List<>
*
* **/
static IList GetProducts()
{
return new List
{
new Product{ ID =1,Price=12},
new Product{ ID =2,Price=22},
new Product{ ID =3,Price=32},
};
}
static Product[] GetProductsArray()
{
return new Product[]
{
new Product{ ID =1,Price=12},
new Product{ ID =2,Price=22},
new Product{ ID =3,Price=32},
};
}
static Dictionary GetProductsDict()
{
return new Dictionary
{
{1, new Product{ ID =1,Price=12}},
{2, new Product{ ID =1,Price=12}},
{3, new Product{ ID =1,Price=12}},
};
}
class Product
{
public int ID { get; set; }
public double Price { get; set; }
}