Exemplo n.º 1
0
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");

            // where are all Generic Collections located in .NET?
            // System.Collections.Generic.

            // while using generics there is not casting or boxing

            // generic list
            var numbers = new GenericList <int>();

            numbers.Add(10);

            var books = new GenericList <Book>();

            books.Add(new Book());

            // generic dictionary
            var dictionary = new GenericDictionary <string, Book>();

            dictionary.Add("1234", new Book());

            // using class with value constraint
            var num = new Nullable <int>(5);

            System.Console.WriteLine("Has Value? " + num.HasValue);
            System.Console.WriteLine("Value: " + num.GetValueOrDefault());

            var numNull = new Nullable <int>();

            System.Console.WriteLine("Has Value? " + numNull.HasValue);
            System.Console.WriteLine("Value: " + numNull.GetValueOrDefault());
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            var book = new Book {
                Isbn = "1332", Title = "C#"
            };

            var numbers = new GenericList <int>();

            numbers.Add(10);

            var books = new GenericList <Book>();

            books.Add(new Book());


            var dictionary = new GenericDictionary <string, Book>();

            dictionary.Add("2213", new Book());

            var number = new Nullable <int>(5);

            System.Console.WriteLine("Has Value ? " + number.HasValue);
            System.Console.WriteLine("Value: " + number.GetValueOrDefault());



            Console.ReadKey();
        }