コード例 #1
0
ファイル: Program.cs プロジェクト: badyornyi/uip_csharp_repo
 public void AddPhone(MobilePhone mobilePhone)
 {
     for (int i = 0; i < MobilePhones.Length; i++)
     {
         if (MobilePhones[i] == null)
         {
             MobilePhones[i] = mobilePhone;
             break;
         }
     }
 }
コード例 #2
0
ファイル: Program.cs プロジェクト: badyornyi/uip_csharp_repo
        static void Main(string[] args)
        {
            // Class 1: Data types

            if (false)
            {
                int rectangleSideA = 30;
                int rectangleSideB = 40;

                int rectangleSquare    = rectangleSideA * rectangleSideB;
                int rectanglePerimeter = 2 * rectangleSideA + 2 * rectangleSideB;

                Console.WriteLine(rectangleSquare);
                Console.WriteLine(rectanglePerimeter);
            }

            if (false)
            {
                int i  = 0;
                int i1 = i--;
                Console.WriteLine(i1);
                Console.WriteLine(i);
                int i2 = --i;
                Console.WriteLine(i2);

                Console.ReadLine();
            }

            if (false)
            {
                int personAge = 19;

                bool isAlcoholSaleRestricted = personAge < 21;
                Console.WriteLine("Alcohol sale restricted: " + isAlcoholSaleRestricted);
                Console.ReadLine();
            }


            // Class 2: if else

            if (false)
            {
                int MINCSHARP  = 30;
                int MINENGLISH = 90;
                int MINSOFT    = 5;

                int personOneCSharp  = 35;
                int personOneEnglish = 95;
                int personOneSoft    = 4;
                int personTwoCSharp  = 25;
                int personTwoEnglish = 90;
                int personTwoSoft    = 6;

                bool isPersonOnePassed = personOneCSharp >= MINCSHARP && (
                    personOneEnglish >= MINENGLISH || personOneSoft >= MINSOFT
                    );

                bool isPersonTwoPassed = personTwoCSharp >= MINCSHARP && (
                    personTwoEnglish >= MINENGLISH || personTwoSoft >= MINSOFT
                    );

                Console.WriteLine("Person 1 passing status is " + isPersonOnePassed);
                Console.WriteLine("Person 2 passing status is " + isPersonTwoPassed);
                Console.ReadLine();


                int currentMark = 4;

                switch (currentMark)
                {
                case 1:
                case 2:
                {
                    Console.WriteLine("Mark is Bad");
                    break;
                };

                case 3:
                {
                    Console.WriteLine("Mark is So-so");
                    break;
                };

                case 4:
                {
                    Console.WriteLine("Mark is Good");
                    break;
                };

                case 5:
                {
                    Console.WriteLine("Excelent");
                    break;
                }

                default:
                {
                    Console.WriteLine("Current Mark is incorrect");
                    break;
                }
                }
                ;

                Console.ReadLine();
            }

            if (false)
            {
                string variableToConvert = Console.ReadLine();
                int    variableParsed;
                bool   isVariableParceble = Int32.TryParse(variableToConvert, out variableParsed);
                if (isVariableParceble)
                {
                    Console.WriteLine("Variable " + variableToConvert + " was successfully converted to int32: " + variableParsed);
                }
                else
                {
                    Console.WriteLine("Variable " + variableToConvert + " couldn't be converted to int32");
                };
                Console.ReadLine();
            }


            // Class 3: Arrays, Cycles

            if (false)
            {
                int[] singleArray = new int[] { 1, 3, 5, 7, 9 };

                for (int i = 0; i < singleArray.Length; i++)
                {
                    //Console.WriteLine("Array element '" + i + "' is: " + singleArray[i]);
                    Console.WriteLine($"Array element '{i}' is: {singleArray[i]}");
                }
            }

            if (false)
            {
                int[][] jaggedArray = new int[][]
                {
                    new int[] { 1, 3, 5, 7, 9 },
                    new int[] { 0, 2, 4, 6 },
                    new int[] { 11, 22 }
                };

                for (int i = 0; i < jaggedArray.Length; i++)
                {
                    for (int j = 0; j < jaggedArray[i].Length; j++)
                    {
                        Console.WriteLine($"Array's array element [{i};{j}] value is: {jaggedArray[i][j]}");
                    }
                }
                ;
            }

            if (false)
            {
                string[] names = new string[]
                {
                    "Roma",
                    "Maksim",
                    "Sasha"
                };

                foreach (string name in names)
                {
                    if (name[0] == 'R')
                    {
                        continue;
                    }
                    Console.WriteLine(name);
                }

                foreach (string name in names)
                {
                    if (name[0] == 'M')
                    {
                        break;
                    }
                    Console.WriteLine(name);
                }
            }

            if (false)
            {
                string dataFromService = "some-data-for-test";
                Random randomizer      = new Random();
                while (dataFromService.Length < 50)
                {
                    Console.WriteLine($"BEFORE: {dataFromService}");
                    int addedNumber = randomizer.Next(0, 10);
                    dataFromService += GetNumberInStringAfterMultiple(addedNumber);
                    Console.WriteLine($"AFTER: {dataFromService}");
                }
            }

            if (false)
            {
                double carPrice            = 10594;
                double startSalary         = 590;
                double increaseSalaryCoeff = 1.15;
                double currentMoneyAmount  = 11000;
                int    experienceLevel     = 2;
                int    numberOfMonthes     = 0;

                while (currentMoneyAmount < carPrice)
                {
                    currentMoneyAmount += startSalary;
                    startSalary         = CalculateSallary(startSalary, increaseSalaryCoeff, experienceLevel);
                    numberOfMonthes    += 1;
                    Console.WriteLine($"Current Month: {numberOfMonthes}");
                    Console.WriteLine($"Current Money Amount: {currentMoneyAmount}");
                    Console.WriteLine($"Next Month Salary: {startSalary}");
                    Console.WriteLine("---------------");
                }

                Console.WriteLine($"Needed number of Monthes to buy car: {numberOfMonthes}");
            }

            // Class 4: Methods

            if (false)
            {
                int first  = 10;
                int second = 20;

                int resultSum = CalculateSum(first, second);
                Console.WriteLine(resultSum);
            }

            if (false)
            {
                Console.WriteLine("How many numbers you want to put?");
                int   valueFromUser       = GetNumberFromUserWithDesiredRange(1, 10);
                int[] arrayValuesFromUser = new int[valueFromUser];
                for (int i = 0; i < valueFromUser; i++)
                {
                    arrayValuesFromUser[i] = GetNumberFromUserWithDesiredRange(100, 1000);
                }
                PrintArray(arrayValuesFromUser);
            }

            if (false)
            {
                bool isExitReauired = false;
                do
                {
                    PrintMenu();
                    int selectedMenuOption = GetNumberFromUserWithDesiredRange(1, 4);
                    switch (selectedMenuOption)
                    {
                    case 1:
                        FillArray();
                        break;

                    case 2:
                    case 3:
                        DoSomething();
                        break;

                    case 4:
                        Console.Clear();
                        break;

                    case 5:
                        isExitReauired = true;
                        break;

                    default:
                    {
                        break;
                    }
                    }
                } while (isExitReauired);
            }

            // Class 4: Classes

            if (false)
            {
                Human human1 = new Human("Alexus", 20, "M");
                Human human2 = new Human("Alice", 19, "F");

                human1.Name = "Ale";
                //human1.Age = 20;
                human1.Sex = "X";

                human2.Name = "Alice";
                //human2.Age = 19;
                human2.Sex = "F";

                human1.SayHello();
                human2.SayHello();
            }

            if (false)
            {
                MobilePhoneShop Shop01 = new MobilePhoneShop("My Shop", "Kyiv", 5);

                MobilePhone[] mobilePhones = new MobilePhone[]
                {
                    new MobilePhone("nokia"),
                    new MobilePhone("siemens")
                };

                Shop01.ReceivePhones(mobilePhones);
            }

            Console.ReadLine();
        }