Jump to content

  • Log In with Google      Sign In   
  • Create Account


#Actualdarookie

Posted 12 August 2012 - 09:52 AM

I don't understand what you mean by "unique name". Each new entry in the list can already be identified by its list index, which is by definition unique with each list (e.g. no two separate instances can have the same list index at the same time).
If you need a way to identify list items given only a reference, you can always add a property to your class like a time stamp or just use the list index:
[source lang="csharp"]// 1) Unique name using time of instantiationclass Market1{ public Market1() { Name = dateTime.UtcNow.Ticks; } long Name { get; private set; }}// 2) Unique name using list index (example only works for single list per class type)class Market2{ // here the constructor not only assign the name but also adds the instance to the list public Market2(IList<Market2> list) { Name = list.Count; list.Add(this); } int Name { get; private set; }}[/source]

#1darookie

Posted 12 August 2012 - 09:52 AM

I don't understand what you mean by "unique name". Each new entry in the list can already be identified by its list index, which is by definition unique with each list (e.g. no two separate instances can have the same list index at the same time).
If you need a way to identify list items given only a reference, you can always add a property to your class like a time stamp or just use the list index:
[source lang="csharp"]// 1) Unique name using time of instantiationclass Market1{ public Market1() { Name = dateTime.UtcNow.Ticks; } long Name { get; private set; }}// 2) Unique name using list index (example only works for single list per class type)class Market2{ // here the constructor not only assign the name but also adds the instance to the list public Market2(IList<Market2> list) { Name = list.Count; list.Add(this); } int Name { get; private set; }}[/source]

PARTNERS