Advertisement
nahidjamalli

Lesson #1

Feb 14th, 2020
326
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.45 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace ConsoleApp1
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             // 3 students
  14.             // NO OOP!
  15.  
  16.             // Student 1
  17.             int age1 = 21;
  18.             string name1 = "Abbas";
  19.  
  20.             // Student 2
  21.             int age2 = 24;
  22.             string name2 = "Kanan";
  23.  
  24.             // Student 3
  25.             int age3 = 20;
  26.             string name3 = "Akif";
  27.  
  28.             // 20.000 students
  29.             // Name
  30.             // Age
  31.  
  32.             // Type-name instance-name
  33.             // A3 - Student
  34.             // A3 blank page = student1
  35.             Student student1 = new Student();
  36.             student1.name = "Saleh";
  37.             student1.age = 19;
  38.  
  39.             Student student2 = new Student();
  40.             student2.name = "Taleh";
  41.             student2.age = 33;
  42.  
  43.             // This object is not initialized
  44.             Student student3;
  45.  
  46.             // Default values
  47.             // integer types => 0
  48.             // floating-point types => 0.0
  49.             // reference types => null
  50.             // Reference Types [string, Student] => class
  51.  
  52.             // Array - Sequence is the same type element list.
  53.             // 78025, 1, 2, 3, 9, -44, 0, 1001, -1000, 563 - Array
  54.             // Array Declaration Syntax:
  55.             // type-name[] object-name = new type-name[elementOfCount];
  56.             float[] mySequence = new float[10];
  57.             mySequence[5] = -44.00F;
  58.  
  59.             // Float type => 4 bytes => 32 bits
  60.             float f1 = 64.85623F;
  61.  
  62.             // Double type => 8 bytes => 64 bits
  63.             double d1 = 64.85623;
  64.  
  65.             // All programming languages BY DEFAULT
  66.             // Type of Integer values => int => 4 bytes => 32 bits
  67.             // Type of Floating values => double
  68.  
  69.             // Infinity looping
  70.             // Initialize Condition  Iteration
  71.             // 1. Initialize => int i = 0;
  72.             // 2. Condition => i < 10
  73.             // 3. Iteration => i++
  74.  
  75.             // Iteration: 2
  76.             // Start value: 5
  77.  
  78.             // 5, 7, 9, 11, 13
  79.  
  80.             // Range: 0 ... 9
  81.             // Odd indexes: 0, 2, 4, 6, 8 [+]
  82.             // Even indexes: 1, 3, 5, 7, 9 [+]
  83.  
  84.             // increment => [i++] [i = i + 1] [i += 1]
  85.             // decrement => [i--] [i = i - 1] [i -= 1]
  86.             /*
  87.             for (int i = 7; i < 17; i = i + 1)
  88.             {
  89.                 // Concat => string join 0 + " => " ======>>>>>>> [0 => ]
  90.                 Console.Write(i - 7 + " => ");
  91.                 Console.WriteLine("{0:f1}", mySequence[i - 7]);
  92.             }
  93.             */
  94.  
  95.             /*
  96.             // 7, 9, 11, 13, 15
  97.             for (int i = 7; i < 17; i = i + 2)
  98.             {
  99.                 // Concat => string join 0 + " => " ======>>>>>>> [0 => ]
  100.                 Console.Write(i - 7 + " => ");
  101.                 Console.WriteLine("{0:f1}", mySequence[i - 7]);
  102.             }
  103.             */
  104.  
  105.             /*
  106.             // 8, 10, 12, 14, 16
  107.             for (int i = 8; i < 17; i = i + 2)
  108.             {
  109.                 // Concat => string join 0 + " => " ======>>>>>>> [0 => ]
  110.                 Console.Write(i - 7 + " => ");
  111.                 Console.WriteLine("{0:f1}", mySequence[i - 7]);
  112.             }
  113.             */
  114.  
  115.             // Array Declaration Syntax:
  116.             // type-name[] object-name = new type-name[elementOfCount];
  117.             Student[] students = new Student[3];
  118.  
  119.             // students.Length = 15; // ERROR!
  120.  
  121.             for (int i = 0; i < students.Length; i++)
  122.             {
  123.                 students[i] = new Student();
  124.  
  125.                 Console.Write("Name: ");
  126.                 students[i].name = Console.ReadLine();
  127.  
  128.                 Console.Write("Age: ");
  129.                 students[i].age = int.Parse(Console.ReadLine());
  130.             }
  131.  
  132.             Console.WriteLine("All entered student list");
  133.             for (int i = 0; i < students.Length; i++)
  134.             {
  135.                 Console.Write("Name #" + (i + 1) + ": ");
  136.                 Console.WriteLine(students[i].name);
  137.  
  138.                 Console.Write("Age #" + (i + 1) + ": ");
  139.                 Console.WriteLine(students[i].age);
  140.             }
  141.         }
  142.  
  143.         private class Student
  144.         {
  145.             // Access modifiers
  146.             public int age;
  147.             public string name;
  148.         }
  149.     }
  150. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement