I am newbie in unity and use C#, actually i am python developer i try to make a list which can holds only unique Values and if some duplicate value come it will not allow to enter in list
List<int> iList = new List<int>();
iList.Add(2);
iList.Add(3);
iList.Add(5);
iList.Add(7);
list =[2,3,5,7]
**in python we just do this to avoid duplicate in list **
if(iList.indexof(value)!=-1){
iList.append(value)
}
But what should we do in C# to achieve very similar results Thanks Your effort will be highly appreciated
C# List has similar method:
if (!iList.Contains(value)) iList.Add(value);
Alternatively you can use a HashSet<int>. There you don't need to add any conditions:
var hasSet = new HashSet<int>();
hashSet.Add(1);
hashSet.Add(1);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With