Пример #1
0
        //Entry point
        public void Main()
        {
            Console.WriteLine(
                "Classes are special kinds of templates from which you can create objects. Each object contains data and methods to manipulate and access that data. " +
                "The class defines the data and the functionality that each object of that class can contain. " +
                "A class declaration consists of a class header and body.The class header includes attributes, modifiers, and the class keyword. " +
                "The class body encapsulates the members of the class, that are the data members and member functions.The syntax of a class declaration is as follows:"
                );
            Console.WriteLine("------------------------------------------------------------------------");
            // object instantiation
            customer obj = new customer();

            //Method calling
            obj.displayData();

            //fields calling
            Console.WriteLine(obj.CustID);
            Console.WriteLine(obj.Name);
            Console.WriteLine(obj.Address);
            Console.WriteLine("------------------------------------------------------------------------");

            Console.WriteLine(
                "Partial classes" + "\n" +
                "Typically, a class will reside entirely in a single file." +
                "However, in situations where multiple developers need access to the same class, then having the class in multiple files can be beneficial." +
                "The partial keywords allow a class to span multiple source files.When compiled, the elements of the partial types are combined into a single assembly. " +
                "There are some rules for defining a partial class as in the following; \n" +
                "1) A partial type must have the same accessibility. \n" +
                "2) Each partial type is preceded with the 'partial' keyword. \n" +
                "3) If the partial type is sealed or abstract then the entire class will be sealed and abstract. \n" +
                "In the following example we are adding two files, partialPart1.cs and partialPart2.cs, and declare a partial class, partialclassDemo, in both classes.");

            //partial class instance
            var obj1 = new PartialClassDemo();

            obj1.method1();
            obj1.method2();
            Console.WriteLine("------------------------------------------------------------------------");

            Console.WriteLine(
                "Static classes " + "\n" +
                "A static class is declared using the 'static' keyword." +
                "If the class is declared as static then the compiler never creates an instance of the class. " +
                "All the member fields, properties and functions must be declared as static and they are accessed by the class name directly not by a class instance object.");

            Console.WriteLine("------------------------------------------------------------------------");
        }