Advertisement
Maniklas

Example

Oct 12th, 2020
2,321
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.70 KB | None | 0 0
  1. //Så när du i vanliga fall ska skriva en metod i en klass så gör du såhär
  2. using windowUtils;
  3.  
  4. public class OfficeManager2020
  5. {
  6.     public Employee vd;
  7.     public Employee[] office;
  8.  
  9.     public void Setup()
  10.     {
  11.         windowUtils.output("Welcome to the setup for Office Manager 2020!\nPlease enter the name of your VD: ");
  12.         string vdName = windowUtils.input();
  13.         windowUtils.output("\nPlease enter age: ");
  14.         int vdAge = int.parse(windowUtils.input());
  15.         vd = new Employee(vdName, vdAge, "VD");
  16.     }
  17.  
  18.     public void newEmployee()
  19.     {
  20.         windowUtils.output("Please enter name:");
  21.         string n = windowUtils.input();
  22.         windowUtils.output("\nPlease enter age:");
  23.         int a = int.parse(windowUtils.input());
  24.         windowUtils.output("\nPlease enter rank:");
  25.         string r = windowUtils.input();
  26.         office[office.length()] = new Employee(n, a, r);
  27.     }
  28.  
  29.     public string employeeInfo(string employeeName)
  30.     {
  31.         string output = "";
  32.         int employeenumber = 0;
  33.         foreach(Employee e in office)
  34.         {
  35.  
  36.         }
  37.     }
  38. }
  39.  
  40. public class Employee
  41. {
  42.     public int age;
  43.     public string name;
  44.     public string rank;
  45.  
  46.     public Employee()       // En constructor metod som används för att skapa ett nytt objekt
  47.     {               // (en instans) med typen som klassen representerar
  48.         age = 0;
  49.         name = "Unknown";
  50.         rank = "unknown"
  51.     }
  52.  
  53.     public Employee(string n, int a, string r)  // En till constructor metod som används på samma sätt
  54.     {                       // men låter en sätta objektets property variabler.
  55.         age = a;
  56.         name = n;
  57.         rank = r;
  58.     }
  59.  
  60.     public string getName()     // En funktion i klassen som i det här fallet returnerar property namn
  61.     {
  62.         return name;
  63.     }
  64.  
  65.     public int getAge()
  66.     {
  67.         return age;
  68.     }
  69.  
  70.     public string getRank()
  71.     {
  72.         return rank;
  73.     }
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement