473,785 Members | 2,283 Online
Bytes | Software Development & Data Engineering Community
+ 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 6854

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

Similar topics

1
2177
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 data/columns/properties in the DataGridView that are not known at compile time. The total number of these data/columns/properties is also not known. So the question is how can I dynamically add properties (indexers don't seem to work) so that DataGridView can show...
8
5610
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 parameters, I can NOT do the following: public TabData Item(int index) { get
12
24813
by: Sergey Klementiev | last post by:
Why it's impossible to have a static indexer in C#?
8
1585
by: Russell Bearden | last post by:
Why are there no indexed properties in C#? For example: class blah { public Node Child { get {
23
391
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
2178
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 the problem is with using plain indexers is. Let's just say I'm confused. :P
4
9866
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 based on their data and some other data as well. i planned on passing it by reference into a function that modified their values. but it gave me the error "you cannot pass indexers and properties by reference". The only way i know of doing it is...
6
3820
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) containing a field, even private, the serialization process would serialize that field too assuming it is needed to that public property. This is not the case ... For example I want to serialize the following class:
2
4185
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 types derived from that base type, or arrays or generic collections of instances of types derived from that base type. All is well until I come to the properties which are generic collections, I don't seem to be able to find an elegant way of...
0
10147
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10083
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8968
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7494
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6737
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5379
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4044
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 we have to send another system
2
3645
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2877
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.