repl.it
@kironroy/

Classes_Structs_Enum

C#

How to create classes. In VS move to cursor to class name, press alt + enter and move to class out of the program file!

fork
loading
Files
  • main.cs
  • Math
  • main.exe
  • notes.txt
  • Person.cs
  • shippingMethod.cs
main.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
using System;

class MainClass {
  public static void Main (string[] args) {
    
    // person class
    
    var john = new Person();
    john.FirstName = "Johnny";
    john.LastName = "Boy";
    john.Introduce();

    // calc class

     var calculator = new Calculator();
     var addResult = calculator.Add(1, 23);
     Console.WriteLine(addResult);

   // coord struct

       // Initialize:   
        CoOrds coords1 = new CoOrds(0,10);
        CoOrds coords2 = new CoOrds(10, 0);

        // Display results:
        Console.Write("CoOrds 1: ");
        Console.WriteLine("x = {0}, y = {1}", coords1.x, coords1.y);

        Console.Write("CoOrds 2: ");
        Console.WriteLine("x = {0}, y = {1}", coords2.x, coords2.y);
  
  // Shipping Method enum

  var method = ShippingMethod.RegeularAirMail;
  Console.WriteLine((int)method);

  var methodId = 2;
  Console.WriteLine((ShippingMethod)methodId);
  
  Console.WriteLine(method.ToString());

  
  }
}