Exemple #1
0
        private static List<string> GetNamesOfCodeFilesInProjectDirectory()
        {
            string path = Directory.GetCurrentDirectory();

            string[] files = Directory.GetFiles(path + @"\..\..", "*.cs");

            var fileNames = new List<string>();

            foreach (var s in files)
            {
                FileInfo fileInfo = new FileInfo(s);
                if (!fileInfo.Name.Equals("Program.cs"))
                    fileNames.Add(fileInfo.Name.Substring(0, fileInfo.Name.Length - 3));
            }

            fileNames.Sort();

            return fileNames;
        }
Exemple #2
0
        public void WorkingWithGenerics()
        {
            Console.WriteLine("\nGenerics");
            GenericEmployeeCollection<GenericEmployeeType> newobj = new GenericEmployeeCollection<GenericEmployeeType>();
            GenericEmployeeType emp1 = new GenericEmployeeType(90, "naynish", 65000);
            GenericEmployeeType emp2 = new GenericEmployeeType(91, "tripti", 75000);
            GenericEmployeeType emp3 = new GenericEmployeeType(92, "jay", 85000);
            GenericEmployeeType emp4 = new GenericEmployeeType(93, "purab", 95000);
            newobj.myGenDictionary.Add(emp1.Id, emp1); newobj.myGenDictionary.Add(emp2.Id, emp2);
            newobj.myGenDictionary.Add(emp3.Id, emp3); newobj.myGenDictionary.Add(emp4.Id, emp4);
            foreach (KeyValuePair<Int32, GenericEmployeeType> item in newobj.myGenDictionary)
            {
                Console.WriteLine(item.Key + " " + item);
            }

            Console.WriteLine("\nGeneric List");
            GenericEmployeeType[] empArr = new GenericEmployeeType[] { emp1, emp2, emp3, emp4 };
            newobj.ShowListEntries<GenericEmployeeType>(empArr);
            Console.WriteLine("\nIncentives: Specifying type parameters for members");
            emp1.Incentives<Int32>(90);

            Fruit[] fruit = new Fruit[]
            {
                new Fruit("apple", 45),
                new Fruit("watermelon", 12),
                new Fruit("peach", 78),
                new Fruit("banana", 10),
            };

            System.Array.Sort<Fruit>(fruit, new ImplementIComparer());
            foreach (Fruit item in fruit)
            {
                Console.WriteLine(item);
            }

            System.Array.Sort<Fruit>(fruit, Fruit.SortByPrice);
            //sorting by price
            Console.WriteLine("\n sorting fruits by price");
            foreach (Fruit item in fruit)
            {
                Console.WriteLine(item);
            }

            //implementing IComparer<OperatingSystems> in the same class
            //collection initialization syntax
            //Note You can only apply collection initialization syntax to classes that support an Add() method, which is
            //formalized by the ICollection<T>/ICollection interfaces.
            List<OperatingSystems> li = new List<OperatingSystems>()
                {
                    new OperatingSystems("WIN32", 900),
                    new OperatingSystems("OSX", 906),
                    new OperatingSystems("LINUX", 400),
                    new OperatingSystems("UBUNTU", 590)
                };
            li.Sort(new OperatingSystems());
            foreach (OperatingSystems item in li)
            {
                Console.WriteLine(item);
            }
        }