Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ublic static class Expansion
- {
- public static double Sum(this List<int> tmp)
- {
- double S = 0;
- foreach (int i in tmp)
- S += i;
- return S;
- }
- }
- public class Good
- {
- public string Title { get; set; }
- public double Weight { get; set; }
- public decimal Price { get; set; }
- public DateTime DateOfArrival { get; set; }
- public int StorageNumber { get; set; }
- //public Good(string _Title, double _Weight, decimal _Price, DateTime _DateOfArrival, int _StorageNumber)
- //{
- // Title = _Title;
- // Weight = _Weight;
- // Price = _Price;
- // DateOfArrival = _DateOfArrival;
- // StorageNumber = _StorageNumber;
- //}
- public void Print()
- {
- Console.WriteLine("{0} - {1} - {2} - {3} - {4}", Title, Weight, Price, DateOfArrival, StorageNumber);
- Console.WriteLine();
- }
- }
- public static class Program
- {
- static void Main(string[] args)
- {
- List<int> arr1 = new List<int>(){ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
- Console.WriteLine("Sum: {0}", arr1.Sum());
- List<Good> goodslist = new List<Good>()
- {
- new Good() { Title = "corn", Weight = 27.1 , Price = 21.5m, DateOfArrival = DateTime.Now.AddDays(1), StorageNumber = 1 },
- new Good() { Title = "ice", Weight = 30, Price = 13m, DateOfArrival = DateTime.Now.AddDays(2), StorageNumber = 1 },
- new Good() { Title = "car", Weight = 1, Price = 5.99m, DateOfArrival = DateTime.Now.AddDays(-3), StorageNumber = 2 },
- new Good() { Title = "toy", Weight = 15.7, Price = 3.75m, DateOfArrival = DateTime.Now.AddDays(6), StorageNumber = 3 },
- new Good() { Title = "biscuit", Weight = 12, Price = 43.6m, DateOfArrival = DateTime.Now.AddDays(8), StorageNumber = 2 }
- };
- var emp = from goods in goodslist
- where goods.Price > 4
- orderby goods.Price descending
- select new
- {
- goods.Title,
- goods.Price
- };
- foreach (var item in emp)
- {
- Console.WriteLine("{0} - {1}", item.Title, item.Price);
- }
- var emp = from goods in goodslist
- where goods.DateOfArrival > DateTime.Now(-1)
- orderby goods.Price descending
- select new
- {
- goods.Title,
- goods.Price
- };
- oderby
- foreach (var item in emp)
- {
- Console.WriteLine("{0} - {1}", item.Title, item.Price);
- }
- var group = from good in goodslist
- group good by good.StorageNumber;
- foreach (var item in group)
- {
- Console.WriteLine(item.Key);
- foreach (var gr in item)
- {
- gr.Print();
- }
- Console.WriteLine();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement