473,320 Members | 1,982 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

template for typed arrays in .NET

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 17 '05 #1
11 1758
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 17 '05 #2
"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 17 '05 #3
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 17 '05 #4
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 17 '05 #5
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 17 '05 #6
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 17 '05 #7
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 17 '05 #8
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 17 '05 #9
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 17 '05 #10
"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 17 '05 #11
"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 17 '05 #12

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

17
by: Jacek Dziedzic | last post by:
Hello! I have a templated class that serves as a simple vector of elements. template <typename T> class simple_vector : public math_object { // ... lots of simple_vector operations // the...
19
by: Canonical Latin | last post by:
"Leor Zolman" <leor@bdsoft.com> wrote > "Canonical Latin" <javaplus@hotmail.com> wrote: > > > ... > >But I'm still curious as to the rational of having type >...
11
by: Boni | last post by:
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:...
35
by: Steven T. Hatton | last post by:
Perhaps I'm just a bit frustrated, and I will soon realize the clear truth of the matter, but right now I have some serious misgivings about the value of investing a lot of time and effort into...
13
by: mike b | last post by:
Hello everyone, thanks in advance for your help. I'm new to C++ templates and have run into some issues using member function templates. I have a shared library containing templates that I'm...
12
by: nooneinparticular314159 | last post by:
Hello. If I declare the following: template<int a, int b, int SomeArray> class DoSomething{ public: .. .. ..
12
by: Peng Yu | last post by:
Hi, Expression template can be used for the implementation of simple operators without using temporaries (e.g. the ones in the book C++ Template). I'm wondering whether expression template is...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.