473,768 Members | 5,334 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

1 New Member
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:Open Light
{}
public class BlackLight:Open Light
{}

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<OpenL ight>> LightList=new List<tool<OpenL ight>>();

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

EX1

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

LightList.Add(L ights);

...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(L ights);
LightList[0].Content = x;
LightList.Add(L ights);
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 1266
GaryTexmo
1,501 Recognized Expert Top Contributor
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
3081
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. My problem, is that after i insert a row, i need to insert another row in a different table that references the first row. To do that i need to know the primary key for the original row. How can i tell what the primary key was? In Oracle, you...
6
1496
by: BR | last post by:
Is there a way to tell what exe is using which version of a .dll in the gac?
2
1189
by: Quentin Huo | last post by:
Hi: I have a parent class "classA", which is like: public abstract class classA { ..... public string ReturnAString() {
2
1315
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
1606
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 "floating point not linked"
14
1500
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 do the following...
6
1505
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 superclass. What is the preferred way to handle such situations. My original thought was to do something like this: class AA(object): def general_method(): pass class A(AA):
3
1841
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 have a snippet of this class: Public Class CustomDDL Inherits DropDownList
8
328
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 make a list class that will store the objects. My question is how do I go about creating the list class...I am assuming it should be a standalone class that uses an arraylist to store the objects. If I go that route how do I instantiate the...
0
916
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 help or information.
0
9576
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10175
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10017
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...
0
9843
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8840
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...
0
6656
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
5283
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...
0
5425
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2808
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.