473,467 Members | 1,307 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

generic properties and indexers

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
{
...
}
}

// impossible
public List<T> this<T>[string listName]
{
get
{
...
}
}

If you ask where such syntax could be handy, then this is concrete scenario:
suppose you need a class that contains a list of generic lists where each
generic list is instantiated with different type.

class ListContainer
{
// can't store list of generic lists in List<> but arraylist is enough
ArrayList lists;
}

class ListContainer
{
public void AddList<T>( List<T> list )
{
lists.Add( list );
}
}

Now you would like a generic indexer...

public List<T> this<T>[ string listName ]
{
get
{
...

....but have to use a method instead

public List<T> GetList<T>( string listName )
{
...

the same applies to properties - you have to use generic methods since
generic properties are not available.

I would be glad to hear your opinion on this issue.

Regards,
Wiktor Zychla

Apr 12 '06 #1
0 6823

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

Similar topics

1
by: Rob | last post by:
Dear All, I have a class that exposes a few properties. These properties are used in a DataGridView. The code for that is shown bellow. The problem is that I also need to show...
8
by: MC D | last post by:
Hi, I'm trying to write a class that inherits from System.Collections.CollectionBase, and I want to expose the Item property for both Get and Set. However because C# doesn't support property...
12
by: Sergey Klementiev | last post by:
Why it's impossible to have a static indexer in C#?
8
by: Russell Bearden | last post by:
Why are there no indexed properties in C#? For example: class blah { public Node Child { get {
23
by: Marcin Grzębski | last post by:
I red MSDN article of C# 2.0 this week... and i found very strange syntax for properties e.g.: public int MyIntValue { get { // ... } protected set { // ... }
2
by: Daniel Miller | last post by:
What is the difference between indexers and indexed properties (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/csref/html/vcwlkindexedpropertiestutorial.asp)? I don't see what...
4
by: tg.foobar | last post by:
i'd like to do the following, but i don't think it's possible. can you help me find a way to do this, or maybe a better way to write the code? I have a list of items that need to be modified...
6
by: Beorne | last post by:
I have to use XmlSerializer to serialize a class and I've found big problems serializing properties and indexers. I assumed that if you serialize a class with public properties (or an indexers)...
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...
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.