コード例 #1
0
        public Program_B()
        {
            var newProg = new Program_A();

            // Program_A protected variable is accessable from Program_B through inheritance
            myProtectedInt1 = 10;

            // Program_A public variable is accessable from Program_B
            newProg.myPublicInt1 = 12;
        }
コード例 #2
0
        static void Main(string[] args)
        {
            var myProg = new Program_A();

            // Program_A private variable is accessable
            myProg.myPrivateInt1 = 10;
            myProg.myPrivateInt2 = 11;

            // Program_A protected variable is accessable
            myProg.myProtectedInt1 = 12;

            // Program_A public int variable is accessable
            myProg.myPublicInt1 = 14;

            // 5. reading text from user input
            Console.Write("Type a number between 1 and 10: ");
            myProg.MyPublicString = Console.ReadLine();


            // 6. Parsing
            int userNumber;

            if (int.TryParse(myProg.MyPublicString, out userNumber) && userNumber <= 10)
            {
            }
            else
            {
                if (userNumber >= 10)
                {
                    Console.WriteLine("Number larger than 10.");
                }
                else
                {
                    Console.WriteLine("Not a number!");
                }
            }

            Console.WriteLine("User wrote: " + myProg.MyPublicString);
            Console.ReadLine();
        }