Aklımda Kalası Kelimeler

* давайте работать вместе
* Zarf ve Mazruf, Zerafet(xHoyratlık) ile aynı kökten(za-ra-fe) gelir
* Bedesten
* Suç subuta ermiştir - Suç sabit olmuştur

20 Ocak 2016 Çarşamba

Linq ile GroupBy ve Sum örneği

using System;
using System.Collections.Generic;
using System.Linq;

namespace ConsoleApplication6
{
    class Tax
    {
        public int Orani;
        public int Amount;
        public int ReasonCode;
        public string Reason;
        public override string ToString()
        {
            return string.Format("Oranı:{0}, Amount:{1}, ReasonCode:{2}, Reason:{3}", Orani,Amount,ReasonCode,Reason);
        }
    }
    class Program
    {
        static void Main(string[] args)
        {

            List lst = new List()
                            {
                                new Tax(){Amount = 10, Orani = 18},
                                new Tax(){Amount = 5, Orani = 18},
                                new Tax(){Amount = 0, Orani = 0, Reason = "351", ReasonCode = 351},
                                new Tax(){Amount = 0, Orani = 0, Reason = "251", ReasonCode = 251},
                                new Tax(){Amount = 6, Orani = 8},
                                new Tax(){Amount = 16, Orani = 8},
                            };
            // Sum Amount
            var total = (from l in lst
                select l.Amount).Sum();
            Console.WriteLine("Toplam Vergi: "+total);

            // GroupBy
            var a = from l in lst
                group l by l.Orani
                into g
                orderby g.Key
                select g;
            foreach (IGrouping g in a)
            {
                Console.WriteLine(g.Key);
                foreach (Tax tax in g)
                {
                    Console.WriteLine(tax);
                }
            }
        }
    }
}
Çıktısı: