Exemplo n.º 1
0
        static void Main(string[] args)
        {
            List <string> list1 = new List <string>()
            {
                "a", "b", "c", "d", "e"
            };
            List <string> list2 = new List <string>()
            {
                "f", "g", "h", "i", "j", "k"
            };
            List <int> list3 = new List <int>()
            {
                1, 2, 3, 4, 5, 6
            };
            List <int> list4 = new List <int>()
            {
                7, 8, 9, 10, 11
            };

            List <int> output = IntermixLists(list3, list4);

            foreach (var item in output)
            {
                //Console.Write($"{ item }, ");
            }
            //Console.WriteLine(); Console.WriteLine();

            GenericObject <string> ob1 = new GenericObject <string>()
            {
                Title = "title11111", GenericProperty = "generic1"
            };
            GenericObject <string> ob2 = new GenericObject <string>()
            {
                Title = "title2222", GenericProperty = "generic2"
            };

            GenericObject <string> output2 = GetLongerTitle2(ob1, ob2);

            //Console.WriteLine(output2.Title);

            //Console.WriteLine(ob1.GenericProperty);
            //Console.WriteLine(ob2.GenericProperty);

            //Console.WriteLine(); Console.WriteLine();

            IObject ob3 = new Object()
            {
                Title = "title11111"
            };
            IObject ob4 = new Object2()
            {
                Title = "title2222"
            };

            IObject output3 = GetLongerTitle2 <IObject>(ob3, ob4);

            Console.WriteLine(output3.Title);

            Console.ReadLine();
        }
Exemplo n.º 2
0
 public static string GetLongerTitle <T>(GenericObject <T> ob1, GenericObject <T> ob2)
 {
     if (ob1.Title != null && ob2.Title != null)
     {
         if (ob1.Title.Length >= ob2.Title.Length)
         {
             return(ob1.Title);
         }
         else
         {
             return(ob2.Title);
         }
     }
     else
     {
         return("Object has no Title property");
     }
 }