Showing results for 
Search instead for 
Do you mean 
Reply
Solved! Go to solution

TaggedObject [] and TaggedObject in c#

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
Solution
Solution
Accepted by topic author Ildon
‎06-02-2016 02:39 AM

Re: TaggedObject [] and TaggedObject in c#

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#

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#

@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.