0

I'm new to c# but need to have it so depending on what d equals , there are a equal number of properties so if d=3 it would be D1, D2, D3, and the same if d=10000 I don't see how I can have a dynamic name for properties that would follow this pattern.

Int d = 2;
class Points 
{
int D1 = 0;
int D2 = 0;
}

1 Answers1

1

You can try to use DynamicObject, to meet your needs.

Tigran
  • 61,654
  • 8
  • 86
  • 123
  • To be honest, if he's new to C#, I would expect that there is a simpler solution than that which he just hasn't thought of. Probably involving a list. I think best to avoid an answer till we know what he wants. – Yair Halberstadt Sep 12 '17 at 18:46
  • @YairHalberstadt: from the code provided it is clear that he wants `D#` properties inside some type where `# = N`, some natural number. Basically add dynamically properties to the type where property name itself is dynamic. – Tigran Sep 12 '17 at 18:48
  • If we get even more granular - maybe OP is actually just trying to store multiple values together and needs an array? – Scott Sep 12 '17 at 18:49
  • Yes but why would he need that? Most experienced programmers only need that in rare edge cases. I can't imagine that this is really neccessary for what he's doing. – Yair Halberstadt Sep 12 '17 at 18:50