C
C#2y ago
!Adiin

❔ Classes

Hello
using System;
Class Program{

Public static void main(string[] args) {

Employee[] employees = new employees[10];

//can I make like this:
for (int i = 0;i < employees. length;i ++) {
employees[i] = new employees[i, "Name" ];
}

}
}

Public class Employee {
private int Id;
private string name;
Public Employee(int Id, string Name) {
this.Id = Id;
this.Name = Name;
}

}
using System;
Class Program{

Public static void main(string[] args) {

Employee[] employees = new employees[10];

//can I make like this:
for (int i = 0;i < employees. length;i ++) {
employees[i] = new employees[i, "Name" ];
}

}
}

Public class Employee {
private int Id;
private string name;
Public Employee(int Id, string Name) {
this.Id = Id;
this.Name = Name;
}

}
Is the command inside for loop works?? I think no How can I add values to the classes in array?
14 Replies
phaseshift
phaseshift2y ago
employees[i] = new Employee(i, "Name" );
!Adiin
!AdiinOP2y ago
This didn't works It's give me error
phaseshift
phaseshift2y ago
you want me to guess the error?
!Adiin
!AdiinOP2y ago
1sec
phaseshift
phaseshift2y ago
employees. length That wont compile. I presume you copied wrong
Henkypenky
Henkypenky2y ago
new employees[10]; //this is wrong also
employees. length // this aswell
Public Employee (int Id, string Name) //also wrong
this.Name = Name; //also wrong
new employees[i, "Name"]; //2 errors here
new employees[10]; //this is wrong also
employees. length // this aswell
Public Employee (int Id, string Name) //also wrong
this.Name = Name; //also wrong
new employees[i, "Name"]; //2 errors here
best thing to do is go error by error and make sure you understand why
!Adiin
!AdiinOP2y ago
Oh ok
Henkypenky
Henkypenky2y ago
so what is wrong about this:
new employees[10];
new employees[10];
how do you create an array of the type you want, let's say int
JakenVeina
JakenVeina2y ago
it's incorrect syntax the syntax is
Henkypenky
Henkypenky2y ago
yeah we got ghosted, teaching lesson avoided
JakenVeina
JakenVeina2y ago
oh you're not asking you're telling
Henkypenky
Henkypenky2y ago
yeah Smadge
TheRanger
TheRanger2y ago
Public, main new employees c# is case sensitive
Accord
Accord2y ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server