473,378 Members | 1,467 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.

making generic list class

Hi,

Im trying to implement a generic list class for a number of 3d object types,
that form a 3d solid model, take the easiest one Point for example,

it contains a Vector3 and a list of other 3d object types
such as surfaces and wires wich also reference this point.

I need to be able to search the list for an exisitng Point
but just using the Vector3, then if its not in the list
to insert a new Point with the given coordinates.

Is there a good/easy way of doing this with a template class
with only specifying the one type ie Point in the template ?
I had problems in that you cant use parameters in a new statement,
nor have static functions in the interface.

I dont realy want to resort to using object as a parameter.

nor do I want to use a list such as <key,valuepair
as the key is in the value. although I dont need it to be fast.

Im stil relativly new to c# and I tried it a few ways using class template
with 2 types but
it was awkward, even trying to use an interface template as the base for the
3d objects.
I keep trying to do the things I know I can do in C++ wich probably isnt so
good.

In the end I found it easier to do a seperate list class for each type,
as trying to use templates I seemed to end up with more helper classes,
and the information was buried under more layers when viewed in the
debugger.

thanks
Colin =^.^=
Nov 25 '07 #1
4 1631
colin <co*********@ntworld.NOSPAM.comwrote:
Im trying to implement a generic list class for a number of 3d object types,
that form a 3d solid model, take the easiest one Point for example,

it contains a Vector3 and a list of other 3d object types
such as surfaces and wires wich also reference this point.

I need to be able to search the list for an exisitng Point
but just using the Vector3, then if its not in the list
to insert a new Point with the given coordinates.
Okay - that sounds like you just need to use List<Pointand then
List<T>.Find with a predicate which matches based on the Vector3.

I'm afraid if that doesn't help, I'm not terribly clear on what you're
trying to do...

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
World class .NET training in the UK: http://iterativetraining.co.uk
Nov 25 '07 #2
"Jon Skeet [C# MVP]" <sk***@pobox.comwrote in message
news:MP*********************@msnews.microsoft.com. ..
colin <co*********@ntworld.NOSPAM.comwrote:
>Im trying to implement a generic list class for a number of 3d object
types,
that form a 3d solid model, take the easiest one Point for example,

it contains a Vector3 and a list of other 3d object types
such as surfaces and wires wich also reference this point.

I need to be able to search the list for an exisitng Point
but just using the Vector3, then if its not in the list
to insert a new Point with the given coordinates.

Okay - that sounds like you just need to use List<Pointand then
List<T>.Find with a predicate which matches based on the Vector3.

I'm afraid if that doesn't help, I'm not terribly clear on what you're
trying to do...

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
World class .NET training in the UK: http://iterativetraining.co.uk
How about Dictionary<point, Vector3?.

Mike.
Nov 25 '07 #3

"Jon Skeet [C# MVP]" <sk***@pobox.comwrote in message
news:MP*********************@msnews.microsoft.com. ..
colin <co*********@ntworld.NOSPAM.comwrote:
>Im trying to implement a generic list class for a number of 3d object
types,
that form a 3d solid model, take the easiest one Point for example,

it contains a Vector3 and a list of other 3d object types
such as surfaces and wires wich also reference this point.

I need to be able to search the list for an exisitng Point
but just using the Vector3, then if its not in the list
to insert a new Point with the given coordinates.

Okay - that sounds like you just need to use List<Pointand then
List<T>.Find with a predicate which matches based on the Vector3.
Aha ok thanks, I remember I did come accross that
but im not familiar with it and it wasnt obvious to me at first glance how
to even use it,
so il have to go have a further read now youve given me a hint it might be
in the right direction.
:)

I kinda like the idea of keeping it simple,
as theres only 3 seperate list types.
after having to use reflection im kinda weary of complicated stuff.
I'm afraid if that doesn't help, I'm not terribly clear on what you're
trying to do...
Well actually I get that feeling too sometimes, ...

I remember hearing somewhere there was so much information being generated
about
windows no one person could ever keep up with the new information let alone
know everything there is to know.

Colin =^.^=
Nov 25 '07 #4
"Michael D. Ober" <obermd.@.alum.mit.edu.nospamwrote in message
news:13*************@corp.supernews.com...
"Jon Skeet [C# MVP]" <sk***@pobox.comwrote in message
news:MP*********************@msnews.microsoft.com. ..
>colin <co*********@ntworld.NOSPAM.comwrote:
>>Im trying to implement a generic list class for a number of 3d object
types,
that form a 3d solid model, take the easiest one Point for example,

it contains a Vector3 and a list of other 3d object types
such as surfaces and wires wich also reference this point.

I need to be able to search the list for an exisitng Point
but just using the Vector3, then if its not in the list
to insert a new Point with the given coordinates.

Okay - that sounds like you just need to use List<Pointand then
List<T>.Find with a predicate which matches based on the Vector3.

I'm afraid if that doesn't help, I'm not terribly clear on what you're
trying to do...

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
World class .NET training in the UK: http://iterativetraining.co.uk

How about Dictionary<point, Vector3?.
hmm my Vector3 can change, ie the point can move,
the point is shared by numerous objects (Ie 3d surfaces)
wich each need to see the updated position.
I hadnt considerd sorting the lists but the following would cuase an issue I
hadnt even thought of before.

quote:-
As long as an object is used as a key in the Dictionary, it must not change
in any way that affects its hash value. Every key in a Dictionary must be
unique according to the dictionary's equality comparer. A key cannot be a
null reference (Nothing in Visual Basic), but a value can be, if the value
type TValue is a reference type.

Il look into Jon's sugestion soon but for now im bogged down with trying to
get XNA to draw the lines for my wire frames as wide as I tell it to in
rather than just 1 pixel wide.

thanks
Colin =^.^=
Nov 25 '07 #5

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

Similar topics

5
by: majm | last post by:
I'm trying to implement strongly typed lists in the 2.0 framework. I'm using VS2005 beta 2. So far, System.Collections.Generic.List appears to be the ideal solution. However, the...
8
by: JAL | last post by:
Here is my first attempt at a deterministic collection using Generics, apologies for C#. I will try to convert to C++/cli. using System; using System.Collections.Generic; using System.Text; ...
2
by: Greg Buchholz | last post by:
/* I've been experimenting with some generic/polytypic programs, and I've stumbled on to a problem that I can't quite figure out. In the program below, I'm trying to define a generic version of...
0
by: Wiktor Zychla [C# MVP] | last post by:
We do have generic classes, methods and delegates. My question is: what reason prevents us from having generic properties and indexers? // impossible public List<T> GetList<T> { get { ... }
3
by: Tigger | last post by:
I have an object which could be compared to a DataTable/List which I am trying to genericify. I've spent about a day so far in refactoring and in the process gone through some hoops and hit some...
0
by: crazyone | last post by:
I've got a gaming framework i'm building and i want to save myself the trouble of reading and writting the complete game data to a custom file and load/save it to an XML file but i'm getting...
4
by: =?Utf-8?B?QkogU2FmZGll?= | last post by:
We have a class that has a public property that is of type List<T>. FXCop generates a DoNotExposeGenericLists error, indicating "System.Collections.Generic.List<Tis a generic collection designed...
13
by: rkausch | last post by:
Hello everyone, I'm writing because I'm frustrated with the implementation of C#'s generics, and need a workaround. I come from a Java background, and am currently writing a portion of an...
2
by: SimonDotException | last post by:
I am trying to use reflection in a property of a base type to inspect the properties of an instance of a type which is derived from that base type, when the properties can themselves be instances of...
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: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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?
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.