473,396 Members | 1,886 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,396 software developers and data experts.

I have List and inheritance problem question pls tell me what I can do

I'm new at c# and I have little problem when use List and Inheritance

I have Inheritance& Like this

public abstract class Light
{}

public class OpenLight:Light
{}

public class WhiteLight:OpenLight
{}
public class BlackLight:OpenLight
{}

White & Black is Inheritance have data I use but not save that why I create

public tool<T> where T:Light
{//in this have data for save and Ignoretype like this
[XmlIgnore]
public T Content { get; set; }}

now I have to create and add to list

public List<tool<OpenLight>> LightList=new List<tool<OpenLight>>();

...then I want to add to type of WhiteLight,BlackLight what is Inheritance of OpenLight but I error when I do like this

EX1

tool<WhiteLight> Lights= new tool<WhiteLight>();

LightList.Add(Lights);

...It not work error and want only add tool<OpenLight>

but I can use like this

EX2

tool<OpenLight> Lights= new
WhiteLight x;
BlackLight y;

LightList.Add(Lights);
LightList[0].Content = x;
LightList.Add(Lights);
LightList[1].Content = y;


It's pass and can use but I don't understand.I want Ex1 work what I can do.

Thank you.
Dec 24 '10 #1
1 1252
GaryTexmo
1,501 Expert 1GB
This is very hard to read, but I think you need to use AddRange, not Add, when adding a list of data to another list.
Dec 29 '10 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Paul | last post by:
I need to insert a row into a table in SQL Server 2000. The primary key for the row is an identity type, so it auto-numbers for me without needing to put in the value in the insert statement. ...
6
by: BR | last post by:
Is there a way to tell what exe is using which version of a .dll in the gac?
2
by: Quentin Huo | last post by:
Hi: I have a parent class "classA", which is like: public abstract class classA { ..... public string ReturnAString() {
2
by: UJ | last post by:
When you are unloading a page, is there anyway to tell what the next page is going to be that you load? TIA.
2
by: venkatesh | last post by:
hai , i am using turboc++ compiler to run my c program. i written an program with structure sa foolws struct s { float x; }y; when i am accessing the variable x it shows the following error...
14
by: petermichaux | last post by:
Hi, Hopefully the group doesn't mind an(other) inheritance question. Maybe the prototype inheritance style is starting to become a low dim light in my brain...probably not yet. ---- If I...
6
by: Jackson | last post by:
I've got an inheritance question and was hoping brighter minds could guide me. I am in the strange situation where some of the methods in a subclass are actually more general than methods in a...
3
by: RSH | last post by:
I have a simple question regarding inheritance in a web form. I have a DropDownList in an aspx form. It is called DropDownList1 I have a class that will be overriding the render event so I...
8
by: RSH | last post by:
Hi, I am working on some general OOP constructs and I was wondering if I could get some guidance. I have an instance where I have a Base Abstract Class, and 4 Derived classes. I now need to...
0
by: wildman | last post by:
Any way to tell what DLLs have been registered in a web project? I know I can browse available objects, but how can I tell which ones where manually registered into the project? Thanks for any...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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?
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:
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.