Example #1
0
        static void Main(string[] args)
        {
            // utilisation de l'API C# (classes internes a C#)
            Console.WriteLine("Hello World!");

            // utilisation des variables
            int num1 = 2;
            int num2 = 4;
            int res  = num1 + num2;

            Console.WriteLine("Result: " + res);

            // utilisation du enum
            var status = EnumStatus.EN_RUPTURE;

            Console.WriteLine("Enum: " + status);

            // if (CONDITION)
            // operateurs ==, !=, >=, <=, >, <
            // operateurs logique && AND, || OR
            // on detaille l'operation
            // status != EnumStatus.EN_STOCK => true (renvoie vrai)
            // num1 == num2 => false
            // l'operation true || false
            // le || ou && s'arretent des qu'il trouvent une valeur
            if (status != EnumStatus.EN_STOCK || num1 == num2)
            {
                Console.WriteLine("Rupture");
            }
            bool a = !true;

            // !a <=> a == false
            if (!a)
            {
                Console.WriteLine("");
            }
            bool b = (num1 == 2);

            if (b)
            {
                Console.WriteLine("It's true!");
            }

            // appeler une methode statique
            VariablesAndTypes.Execute();
            Arrays.Execute();
            Lists.Execute();
            Loops.Execute();
        }
Example #2
0
        static void Main(string[] args)
        {
            //-----------------------------------------------------------------
            //this code displays a message to the console
            #if (DEBUG)
            Console.WriteLine("Entering debug mode...");
#else
            Console.WriteLine("Entering release mode");
#endif
            //------------------------------------------------------------------
            //Console.WriteLine(CalculateYears(1000, 0.05, 0.18, 2000));
            Loops loops = new Loops();
            //loops.Exercise1();
            //loops.Exercise2();
            loops.Exercise3();


            //Environment.CurrentDirectory = Environment.GetEnvironmentVariable("TEMP");
            //DirectoryInfo info = new DirectoryInfo(".");

            //Console.WriteLine("Directory Info:  " + info.FullName);

            //float[] grades = new float[3];
            //grades[0] = 89.1f;
            //grades[1] = 96.3f;
            //grades[2] = 71.4f;

            //USING THREADS
            //bool stopped = false;


            //Thread t = new Thread(new ThreadStart(() =>
            //    {
            //        var c = 0;
            //        while (!stopped)
            //        {

            //            Console.WriteLine("Running... {0}", c);
            //            Thread.Sleep(2000);
            //            c++;
            //        }
            //}));
            //t.Start();
            //Console.WriteLine("Press any key to exit");
            //Console.ReadKey();
            //stopped = true;
            //t.Join();



            //while (true)
            //{
            //    Console.Write("Type your name: ");
            //    var input = Console.ReadLine();

            //    if (!String.IsNullOrWhiteSpace(input))
            //    {
            //        Console.WriteLine("@Echo: " + input);
            //        continue;
            //    }

            //    break;


            //}


            /*GENERATING RANDOM PASSWORD*/

            //var random = new Random();

            //for (int i = 0; i < 10; i++)
            //{
            //    Console.Write((char)random.Next(97, 122));
            //}
            //Console.ReadKey();


            //const int passwordLength = 10;
            //var buffer = new char[passwordLength];
            //for (int i = 0; i < passwordLength; i++)
            //{
            //    buffer[i] = (char)('a' + random.Next(0, 26));
            //}
            //var password = new string(buffer);
            //Console.WriteLine(password);
            //Console.ReadKey();

            /*GENERATING RANDOM PASSWORD*/

            //Exercise1();

            //SpeechSynthesizer synth = new SpeechSynthesizer();
            //SetTimer();
            //Console.WriteLine("\nPress the Enter key to exit the application...\n");
            //Console.WriteLine("The application started at {0:HH:mm:ss.fff},", DateTime.Now);

            //Console.ReadLine();
            //aTimer.Stop();
            //aTimer.Dispose();
            //Console.WriteLine("Terminating the application");


            //double o = 4.0;
            //double p = 12.0;
            //Console.WriteLine("{0:.0}",o +p);
            //Console.WriteLine($"The number {o} plus {p} is equal to --> {o+p}.0");


            //ViewMetadata(@"C:\Users\obaidka\TestFolder\hello.txt");


            //Comparing Nullable<T> Instances
            //int? i = 42;
            //int? j = 42;
            //bool areEqual = i == j;

            //Console.WriteLine($"i and j are equal? {areEqual}");

            PlayerCharacter[] players = new PlayerCharacter[]
            {
                new PlayerCharacter {
                    Name = "Sarah"
                },
                new PlayerCharacter(), //Name = null
                null                   // PlayerCharacter = null
            };

            string p1 = players?[0]?.Name;
            string p2 = players?[1]?.Name;
            string p3 = players?[2]?.Name;

            Console.ReadLine();

            //if (player1.DaysSinceLastLogin.HasValue)
            //{
            //    Console.WriteLine(player1.DaysSinceLastLogin.Value);
            //}
            //else
            //{
            //    Console.WriteLine("No value for Days since last login");

            //}


            //////////////////////////////////////////////////////
            //int days = player1.DaysSinceLastLogin ?? -1;
            //int days = player1.DaysSinceLastLogin ?? -1;
            //int days = player1.DaysSinceLastLogin.HasValue ? player1.DaysSinceLastLogin.Value : -1;
            //Console.WriteLine($"{days} days since last login");
        }//Main()