I have a two classes` Employee and Controller,Employee's fields is` name,surname,sallary.in Controller class I have a Generic array which has 4 Objects, like this`
public List<employee> e = new List<employee>()
{
new Employee("Vazgen","Vazgenyan",3000$),
new Employee("Petros","Petrosyan",3500$),
new Employee("Poghos","Poghosyan",2000$),
new Employee("Karen","Matevosyan",4000$),
};
I must create Function which name is Insert_Data,i must input datas in Console with commas`John,Williams,5000.I must to divide it from commas, the result will be 3 word in array`{ "John", "Williams", "5000"}.With these data I need to create a new Employee and add to my generic array.How can i do it?
Main
Controller c = new Controller();
c.Insert_Data();
when i will call Insert_Data function, it will ask me` Please type new Employee's data
I will write John,Williams,5000 then it will add my new data in Array and will show me,like this`
"Vazgen","Vazgenyan",3000
"Petros","Petrosyan",3500
"Poghos","Poghosyan",2000
"Karen","Matevosyan",4000
"John", "Williams", 5000
What I have tried:
I tried like this`
class Controller
{
public List<employee> e = new List<employee>()
{
new Employee("Vazgen","Vazgenyan",3000),
new Employee("Petros","Petrosyan",3500),
new Employee("Poghos","Poghosyan",2000),
new Employee("Karen","Matevosyan",4000),
};
public void Insert_Data()
{
Console.WriteLine("Please type new Emplyoee's data");
string text = Console.ReadLine();
string[] arr = text.Split(',');
}
}
<pre>class Employee
{
public string name;
public string surname;
public int sallary;
public Employee(string a, string b, int c)
{
this.name = a;
this.surname = b;
this.sallary = c;
}
}
<pre>static void Main(string[] args)
{
Controller c = new Controller();
int x;
while (true)
{
Console.WriteLine("\nBelow are list of commands, type one of them to start working.");
Console.WriteLine("\n1.Insert\n2.Delete\n3.List\n4.Help");
Console.Write("\nWhat do you want to do: ");
x = int.Parse(Console.ReadLine());
Console.WriteLine();
switch (x)
{
case 1:
c.Insert_Data
break;
case 2:
c.Delete_Data
break;
}
}
}