cancel
Showing results for 
Search instead for 
Did you mean: 

TaggedObject [] and TaggedObject in c#

Pioneer
Pioneer

Hi Guys,

Is it possible to add a taggedObject to an Array of TaggedObject[].

Because the add function isn't available to the taggedObject[].

 

Thanks !

3 REPLIES

Re: TaggedObject [] and TaggedObject in c#

Siemens Phenom Siemens Phenom
Siemens Phenom

You can use Array.Resize() - https://msdn.microsoft.com/en-us/library/bb348051(v=vs.110).aspx

 

Or, you could use ArrayLists, which are inherently dynamic, from the start - https://msdn.microsoft.com/en-us/library/system.collections.arraylist(v=vs.110).aspx

Re: TaggedObject [] and TaggedObject in c#

Siemens Phenom Siemens Phenom
Siemens Phenom

ArrayLists are very flexible, but they are generally frowned upon these days. The problem is that they side-step strong typing, and they have some performance problems. If you don't care about these, then go ahead with an ArrayList.

 

Most people would recommend use of List(Of TaggedObject), instead. This is strongly typed, faster, and it has the "Add" method you wanted.

山田
yamada

Re: TaggedObject [] and TaggedObject in c#

Siemens Phenom Siemens Phenom
Siemens Phenom

@Yamada is correct. I used the wrong name. The strongly typed list is a better choice, and is also easier to use when feeding a function that expects and array - the .ToArray() method returns an array of the correct type, eliminating any need for type casting.