By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
464,822 Members | 1,006 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 464,822 IT Pros & Developers. It's quick & easy.

template for typed arrays in .NET

P: n/a
Dear all,
currently I only found a possibility to create for each type it's own typed
array. I am sick to create for each of my types a separate array class.
In C++ there are so called templates: template<T > class...
Is it possible in VB or c#? Can you give me an example?
Thanks,
Boni
Nov 21 '05 #1
Share this Question
Share on Google+
11 Replies

P: n/a
Hi,

VS.Net 2005 will support generics.

http://msdn.microsoft.com/library/de...5_generics.asp

Ken
-------------------
"Boni" <oilia@nospam> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
Dear all,
currently I only found a possibility to create for each type it's own typed
array. I am sick to create for each of my types a separate array class.
In C++ there are so called templates: template<T > class...
Is it possible in VB or c#? Can you give me an example?
Thanks,
Boni

Nov 21 '05 #2

P: n/a
"Boni" <oilia@nospam> schrieb:
currently I only found a possibility to create for each type it's own
typed array. I am sick to create for each of my types a separate array
class.


I don't see any reason for creating array classes. You can simply create a
typed array using VB.NET's array syntax:

\\\
Dim foo(9) As MyType
....
///

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 21 '05 #3

P: n/a
I create them for typing ArrayList and Hashtable classes, perhaps this is
what he means?

"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:e8****************@TK2MSFTNGP12.phx.gbl...
"Boni" <oilia@nospam> schrieb:
currently I only found a possibility to create for each type it's own
typed array. I am sick to create for each of my types a separate array
class.


I don't see any reason for creating array classes. You can simply create
a typed array using VB.NET's array syntax:

\\\
Dim foo(9) As MyType
...
///

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 21 '05 #4

P: n/a
What should I do If I nees an arraylist of unknown size or other collection?
I don't see any reason for creating array classes. You can simply create
a typed array using VB.NET's array syntax:


What should I do If I nees an arraylist of unknown size or other collection
type?
Nov 21 '05 #5

P: n/a
If you want to more strongy type an arraylist, derive a new class from
collectionbase and override some of the base class methods.
"Boni" <oilia@nospam> wrote in message
news:uP**************@TK2MSFTNGP09.phx.gbl...
What should I do If I nees an arraylist of unknown size or other
collection?
I don't see any reason for creating array classes. You can simply create
a typed array using VB.NET's array syntax:


What should I do If I nees an arraylist of unknown size or other
collection type?

Nov 21 '05 #6

P: n/a
Boni wrote:
What should I do If I nees an arraylist of unknown size or other collection
type?


I think you're really talking about collection classes, aren't you? In
..NET 1, the usual way is to derive those from CollectionBase to create
collections that are typed by providing methods that have typed
signatures. In .NET 2, Generics provide typed collection classes like
List<T> out of the box, and there's PowerCollections
(http://www.wintellect.com/powercollections/) if you need additional
specialised collection implementations.
Oliver Sturm
--
omnibus ex nihilo ducendis sufficit unum
Spaces inserted to prevent google email destruction:
MSN oliver @ sturmnet.org Jabber sturm @ amessage.de
ICQ 27142619 http://www.sturmnet.org/blog
Nov 21 '05 #7

P: n/a
Hi,

You could do

foreach( MyType t in arraylist )
{}

you will get an exception if any of the elements of arraylist is not of
castable to MyType
cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"Boni" <oilia@nospam> wrote in message
news:uP**************@TK2MSFTNGP09.phx.gbl...
What should I do If I nees an arraylist of unknown size or other
collection?
I don't see any reason for creating array classes. You can simply create
a typed array using VB.NET's array syntax:


What should I do If I nees an arraylist of unknown size or other
collection type?

Nov 21 '05 #8

P: n/a
Yes I am. 2005 and .NET 2 are still in Beta so I can't use them in a
production environment. However, with generics this question will become
obsolete as you will be able to write something like Dim x as New
ArrayList<myClass>, I assume (I haven't looked into it yet).


"Oliver Sturm" <ol****@sturmnet.org> wrote in message
news:eN**************@TK2MSFTNGP10.phx.gbl...
Boni wrote:
What should I do If I nees an arraylist of unknown size or other
collection type?


I think you're really talking about collection classes, aren't you? In
.NET 1, the usual way is to derive those from CollectionBase to create
collections that are typed by providing methods that have typed
signatures. In .NET 2, Generics provide typed collection classes like
List<T> out of the box, and there's PowerCollections
(http://www.wintellect.com/powercollections/) if you need additional
specialised collection implementations.
Oliver Sturm
--
omnibus ex nihilo ducendis sufficit unum
Spaces inserted to prevent google email destruction:
MSN oliver @ sturmnet.org Jabber sturm @ amessage.de
ICQ 27142619 http://www.sturmnet.org/blog

Nov 21 '05 #9

P: n/a
Get the Visual Studio 2005 Beta 2 and do something like this:

C#:

List<MyType> myList = new List<MyType>();

Now you can use the strictly typed List<> object to Add(), Insert() and
traverse a list of MyType objects.

The VS 2005 Beta 2 does, indeed, rock!
--
// Anders Tornblad, Systems Developer at Visma Spcs, Sweden
"Boni" wrote:
Dear all,
currently I only found a possibility to create for each type it's own typed
array. I am sick to create for each of my types a separate array class.
In C++ there are so called templates: template<T > class...
Is it possible in VB or c#? Can you give me an example?
Thanks,
Boni

Nov 21 '05 #10

P: n/a
"Robin Tucker" <id*************************@reallyidont.com> schrieb:
I create them for typing ArrayList and Hashtable classes, perhaps this is
what he means?


I don't consider arraylists and hashtables to be arrays...

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>
Nov 21 '05 #11

P: n/a
"Anders Tornblad, SPCS, Sweden" <anders dot tornblad at telia dot com
nospamplease> schrieb:
Get the Visual Studio 2005 Beta 2 and do something like this:

C#:

List<MyType> myList = new List<MyType>();

Now you can use the strictly typed List<> object to Add(), Insert() and
traverse a list of MyType objects.


In VB 2005:

\\\
Dim MyList As New List(Of MyType)
///

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 21 '05 #12

This discussion thread is closed

Replies have been disabled for this discussion.