473,378 Members | 1,426 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,378 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 21 '05 #1
11 1594
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
"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
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
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
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
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
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
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
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
"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
"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 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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
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...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.