Answer the question
In order to leave comments, you need to log in
Who can help with the OOP problem?
Hello everyone, we started to study OOP, this is the task, I wrote it myself according to the way I know, using an example, but the
code errors
namespace OOP4
{
class PatchCord
{
private string name;
private string type;
private int length;
public PatchCord(string name, string type, int length)
{
this.name = name;
this.type = type;
this.length = length;
}
}
class PatchCords
{
PatchCord[] patchCords = new PatchCord[5];
public PatchCord this[int length]
{
set { patchCords[length] = value; }
}
}
class Program
{
static void Main(string[] args)
{
PatchCords A = new PatchCords();
A[0] = new PatchCord("sds","dsd", 2);
for (int i = 0; i < 2; i++)
{
Console.Write(A[i].length);
}
}
}
}
Answer the question
In order to leave comments, you need to log in
Well, look
While, of course, it’s not clear what kind of errors you are getting
And if you wrote them, things would go faster
For now, I can say that it’s not very clear here
class PatchCords
{
PatchCord[] patchCords = new PatchCord[5];
public PatchCord this[int length]
{
set { patchCords[length] = value; }
}
}
class PatchCords
{
PatchCord[] patchCords;
public PatchCords(int size){
patchCords = new PatchCord[size];
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question