コード例 #1
0
        static void Main(string[] args)
        {
            Console.WriteLine("***** Fun with Static Data *****\n");
            //SavingsAccount s1 = new SavingsAccount(50);
            //SavingsAccount s2 = new SavingsAccount(100);
            //SavingsAccount s3 = new SavingsAccount(10000.75);

            //Console.WriteLine("Account balance for s1: {0}, interest rate {1}", s1.currBalance, SavingsAccount.currInterestRate);
            //Console.WriteLine("Account balance for s2: {0}, interest rate {1}", s2.currBalance, SavingsAccount.currInterestRate);
            //Console.WriteLine("Account balance for s3: {0}, interest rate {1}", s3.currBalance, SavingsAccount.currInterestRate);

            SavingsAccount s1 = new SavingsAccount(50);

            //  Print the current interest rate.
            Console.WriteLine("Interest Rate is: {0}", SavingsAccount.GetInterestRate());
            //  Try to change the interest rate.
            SavingsAccount.SetInterestRate(0.08);
            //  Make a second account.
            SavingsAccount s2 = new SavingsAccount(100);

            //  Should print 0.08...right?
            //  Using static constructor
            //  Print the current interest rate.
            Console.WriteLine("Interest Rate is: {0}", SavingsAccount.GetInterestRate());

            //  Make new object, this does NOT 'reset' the interest rate.
            SavingsAccount s3 = new SavingsAccount(10000.75);

            Console.WriteLine("Interest Rate is: {0}", SavingsAccount.GetInterestRate());
        }
コード例 #2
0
        static void Main(string[] args)
        {
            Console.WriteLine("***** Fun with Static Data *****\n");
            SavingsAccount s1 = new SavingsAccount(50);

            // Print the current interest rate.
            Console.WriteLine("Interest Rate is: {0}", SavingsAccount.GetInterestRate());

            // Try to change the interest rate via property.
            SavingsAccount.SetInterestRate(0.08);

            // Make a second account.
            SavingsAccount s2 = new SavingsAccount(100);

            // Print the current interest rate.
            Console.WriteLine("Interest Rate is: {0}", SavingsAccount.GetInterestRate());

            // Make new object, this does NOT 'reset' the interest rate.
            SavingsAccount s3 = new SavingsAccount(10000.75);

            Console.WriteLine("Interest Rate is: {0}", SavingsAccount.GetInterestRate());

            // Print the current interest rate via property.
            Console.WriteLine("Interest Rate is: {0}", SavingsAccount.InterestRate);

            Console.ReadLine();
        }
コード例 #3
0
        public static void Main(string[] args)
        {
            Console.WriteLine("Simple Saving Account Class");

            //three instances of SavingAccount

            SavingsAccount s1 = new SavingsAccount(50);

            SavingsAccount s3 = new SavingsAccount(10000.75);

            Console.WriteLine($" Interest Rate is {SavingsAccount.GetInterestRate()}");


            /**
             *  The static data is shared by all objects of same
             *  category meaning .. currInterestRate is same for
             *  all savingAccount s1,s2 and s3 or any other created
             */

            //pring the current InterestRate
            Console.WriteLine($" Interest Rate is {SavingsAccount.GetInterestRate()}");
            SavingsAccount.SetInterestRate(0.8);

            SavingsAccount s4 = new SavingsAccount(10000.75);

            Console.WriteLine($" Interest Rate is {SavingsAccount.GetInterestRate()}");
            SavingsAccount s2 = new SavingsAccount(100);

            Console.WriteLine($" Interest Rate is {SavingsAccount.GetInterestRate()}");


            // Calling Static Class
            TimeUtilClass.PrintDate();
            TimeUtilClass.PrintTime();
        }
コード例 #4
0
        static void Main(string[] args)
        {
            // Исполняющая система вызывает статический конструктор всего один раз для этого экземпляра приложения
            // когда создает первый раз экземпляр класса
            // или перед первым обращением к статическому члену этого класса
            // (даже до того момента когда будет дана команда создать первый экземпляр класса)
            Console.WriteLine("Interest Rate is: {0}", SavingsAccount.GetInterestRate());

            // Создать счет
            SavingsAccount s1 = new SavingsAccount(50);

            // Вывести текущую процентную ставку
            Console.WriteLine("Interest Rate is: {0}", SavingsAccount.GetInterestRate());

            // изменение процентной ставки
            SavingsAccount.SetInterestRate(0.08);

            // Создать второй счет
            SavingsAccount s2 = new SavingsAccount(100);

            // Вывести текущую процентную ставку
            Console.WriteLine("Interest Rate is: {0}", SavingsAccount.GetInterestRate());

            Console.ReadLine();
        }
コード例 #5
0
ファイル: Program.cs プロジェクト: 0l3shka/lab-1
        static void Main(string[] args)
        {
            Console.WriteLine("***** Fun with Static Data ******\n");
            SavingsAccount s1 = new SavingsAccount();

            Console.WriteLine("Interest Rate is {0}", SavingsAccount.GetInterestRate());
            SavingsAccount.SetInterestRate(0.08);
            SavingsAccount s2 = new SavingsAccount();

            //SavingsAccount s3 = new SavingsAccount(10000.75);
            Console.WriteLine("Interest Rate is {0}", SavingsAccount.GetInterestRate());
            Console.ReadLine();
        }
コード例 #6
0
        private static void Main(string[] args)
        {
            Console.WriteLine("***** Fun with Static Data *****\n");
            var s1 = new SavingsAccount(50);

            Console.WriteLine("Interest Rate is: {0}", SavingsAccount.GetInterestRate());

            SavingsAccount.SetInterestRate(0.08);
            var s2 = new SavingsAccount(100);

            Console.WriteLine("Interest Rate is: {0}", SavingsAccount.InterestRate);

            Console.ReadLine();
        }
コード例 #7
0
        static void Main(string[] args)
        {
            Console.WriteLine("***** Fun with Static Data *****\n");
            // Make an account.
            SavingsAccount s1 = new SavingsAccount(50);

            // Print the current interest rate.
            Console.WriteLine("Interest Rate is: {0}", SavingsAccount.GetInterestRate());
            // Try to change the interest rate via property.
            SavingsAccount.SetInterestRate(0.08);
            // Make a second account.
            SavingsAccount s2 = new SavingsAccount(100);

            // Should print 0.08...right??
            Console.WriteLine("Interest Rate is: {0}", SavingsAccount.GetInterestRate());
            Console.ReadLine();
        }
コード例 #8
0
ファイル: Program.cs プロジェクト: orealse/laboratorywork1
        static void Main(string[] args)
        {
            Console.WriteLine("***** Fun with Static Data *****\n");
            //Создать счет.
            SavingsAccount s1 = new SavingsAccount(50);

            //Вывести текущую процентную ставку.
            Console.WriteLine("Interest Rate is {0}", SavingsAccount.GetInterestRate());

            // Попытаться изменить процентную ставку через свойство.
            SavingsAccount.SetInterestRate(0.08);

            //Создать второй счет.
            SavingsAccount s2 = new SavingsAccount(100);

            // Должен вывести 0.08.... не так ли??
            //Создать новый объект; это не сбросить процентную ставку.
            //SavingsAccount s3 = new SavingsAccount(10000.75);
            Console.WriteLine("Interest Rate is {0}", SavingsAccount.GetInterestRate());
            Console.ReadLine();
        }
コード例 #9
0
ファイル: Program.cs プロジェクト: NathanConnors/C-.NET
        static void Main(string[] args)
        {
            Console.WriteLine("Static data member with objects practice");

            // Instantiate object.
            SavingsAccount s1 = new SavingsAccount(50);

            // Print the current interest rate.
            Console.WriteLine("Interest rate is: {0}", SavingsAccount.GetInterestRate());

            // Try to change the interest rate via property.
            SavingsAccount.SetInterestRate(0.08);

            // Proves change worked.
            Console.WriteLine("Interest rate is: {0}", SavingsAccount.GetInterestRate());

            // When new object is made it resets interest rate.
            SavingsAccount s2 = new SavingsAccount(100);

            Console.WriteLine("Interest rate is: {0}", SavingsAccount.GetInterestRate());

            Console.ReadLine();
        }