0

So I have the following and it seems incorrect.

var classAsm =  assembly.GetExportedTypes().Where(o => o.FullName == "iControl.CommonAddressPort").First();
Array propertyOfPorts = Array.CreateInstance (classAsm, 1,1);

What I wanted to achieve is to assign values to propertyOfPorts since there are 2 (address - string, and port - long) such as this one:

propertyOfPorts.address = "12.2.2.2";
propertyOfPorts.port = 80;

Any help is appreciated.

1 Answer 1

1

I personally would first make a class, then use a list.

public class PortProperties {
    public String Address { get; set; }
    public long Port { get; set; }
}

Then initialize the list:

var propertiesOfPorts = new List<PortProperties>();

Then add it:

propertiesOfPorts.add( new PortProperties {
    Address = "12.2.2.2",
    Port = 80
});

Then use it:

PortProperties firstPort = propertiesOfPorts[0];
String address = firstPort.Address;
long port = firstPort.Port

Using this method, it is easy to define exactly what you want. Otherwise 2D arrays, or 3D arrays get really confusing. For example, maybe for each of those ports I need to define another list of other such information related to that particular port (therefore making this a potential 3D array), I'd just include a list object in the PortProperties class, simple and easy to understand.

public class PortProperties {
    public String Address { get; set; }
    public long Port { get; set; }
    public List<String> otherPropList { get; set; }
}
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you @Gerneio, the only thing is that these properties already exist in "iControl.CommonAddressPort" which is a 3rd partly dll (SDK). But I think you opened up and idea for me on how to tackle this.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.