473,698 Members | 2,179 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

about List and InnerList in class CollectionBase

Hello!

Here I have a collection class Cards which is derived from the Base class
CollectionBase.
This class Cards is a container for Card object.
Now to my question at the bottom of this class we have a method called
Contains.
It gived the same result to use InnerList and List in this method Contains.
I can also just replace List with InnerList in the method Add and it works.

So is the InnerList the same as List because I can use whichever of these
two ?
public class Cards : CollectionBase
{
public Cards() {}

public void Add(Card newCard)
{
List.Add(newCar d);
}

public void Remove(Card oldCard)
{
List.Remove(old Card);
}

public Card this[int cardIndex]
{
get { return (Card)List[cardIndex]; }
set { List[cardIndex] = value; }
}

public void CopyTo(Cards targetCards)
{
for (int index = 0; index < this.Count; index++)
targetCards[index] = this[index];
}

public bool Contains(Card card)
{
bool test1,test2;
test1 = InnerList.Conta ins(card);
test2 = List.Contains(c ard);
return true;

}
}

//Tony
Jun 27 '08 #1
5 4838
Hi Tony,

The difference is that InnerList returns a losely connected ArrayList which
will not trigger the On* methods when manipulated. List will return an IList
which will trigger the On* methods when manipulated.

class MyCollection : CollectionBase
{
protected override void OnInsert(int index, object value)
{
base.OnInsert(i ndex, value);
}

public void Add(object value)
{
List.Add(value) ; // Will trigger OnInsert
InnerList.Add(v alue); // Will not trigger OnInsert
}
}
--
Happy Coding!
Morten Wennevik [C# MVP]
"Tony" wrote:
Hello!

Here I have a collection class Cards which is derived from the Base class
CollectionBase.
This class Cards is a container for Card object.
Now to my question at the bottom of this class we have a method called
Contains.
It gived the same result to use InnerList and List in this method Contains.
I can also just replace List with InnerList in the method Add and it works.

So is the InnerList the same as List because I can use whichever of these
two ?
public class Cards : CollectionBase
{
public Cards() {}

public void Add(Card newCard)
{
List.Add(newCar d);
}

public void Remove(Card oldCard)
{
List.Remove(old Card);
}

public Card this[int cardIndex]
{
get { return (Card)List[cardIndex]; }
set { List[cardIndex] = value; }
}

public void CopyTo(Cards targetCards)
{
for (int index = 0; index < this.Count; index++)
targetCards[index] = this[index];
}

public bool Contains(Card card)
{
bool test1,test2;
test1 = InnerList.Conta ins(card);
test2 = List.Contains(c ard);
return true;

}
}

//Tony
Jun 27 '08 #2
Hello!

Will it be some performance effect if a use List insted of InnerList when
not having any OnInsert(...)

//Tony

"Morten Wennevik [C# MVP]" <Mo************ @hotmail.comskr ev i meddelandet
news:B9******** *************** ***********@mic rosoft.com...
Hi Tony,

The difference is that InnerList returns a losely connected ArrayList
which
will not trigger the On* methods when manipulated. List will return an
IList
which will trigger the On* methods when manipulated.

class MyCollection : CollectionBase
{
protected override void OnInsert(int index, object value)
{
base.OnInsert(i ndex, value);
}

public void Add(object value)
{
List.Add(value) ; // Will trigger OnInsert
InnerList.Add(v alue); // Will not trigger OnInsert
}
}
--
Happy Coding!
Morten Wennevik [C# MVP]
"Tony" wrote:
Hello!

Here I have a collection class Cards which is derived from the Base
class
CollectionBase.
This class Cards is a container for Card object.
Now to my question at the bottom of this class we have a method called
Contains.
It gived the same result to use InnerList and List in this method
Contains.
I can also just replace List with InnerList in the method Add and it
works.

So is the InnerList the same as List because I can use whichever of
these
two ?
public class Cards : CollectionBase
{
public Cards() {}

public void Add(Card newCard)
{
List.Add(newCar d);
}

public void Remove(Card oldCard)
{
List.Remove(old Card);
}

public Card this[int cardIndex]
{
get { return (Card)List[cardIndex]; }
set { List[cardIndex] = value; }
}

public void CopyTo(Cards targetCards)
{
for (int index = 0; index < this.Count; index++)
targetCards[index] = this[index];
}

public bool Contains(Card card)
{
bool test1,test2;
test1 = InnerList.Conta ins(card);
test2 = List.Contains(c ard);
return true;

}
}

//Tony


Jun 27 '08 #3

"Tony" wrote:
Hello!

Will it be some performance effect if a use List insted of InnerList when
not having any OnInsert(...)

//Tony
There is a tiny overhead when using List vs InnerList, but it is only
visible when using large collections (>1 000 000 items) and even then
measurable in milliseconds. Most likely this wouldn't be the bottleneck in
performance issues even then. If you need to override
CollectionBase-behaviour, use List, if you don't, or if you want to
circumvent overridden behaviour, use InnerList.

--
Happy Coding!
Morten Wennevik [C# MVP]

Jun 27 '08 #4
Hello!!

I just wonder does this OnInsert(...)
actually do anything when I'm not overriding it.

//Tony

"Morten Wennevik [C# MVP]" <Mo************ @hotmail.comskr ev i meddelandet
news:2B******** *************** ***********@mic rosoft.com...
>
"Tony" wrote:
Hello!

Will it be some performance effect if a use List insted of InnerList
when
not having any OnInsert(...)

//Tony

There is a tiny overhead when using List vs InnerList, but it is only
visible when using large collections (>1 000 000 items) and even then
measurable in milliseconds. Most likely this wouldn't be the bottleneck
in
performance issues even then. If you need to override
CollectionBase-behaviour, use List, if you don't, or if you want to
circumvent overridden behaviour, use InnerList.

--
Happy Coding!
Morten Wennevik [C# MVP]

Jun 27 '08 #5
Hi Tony,

I'm not sure if anything happens during the On* events. If you are using
Visual Studio 2008 you can easily see for yourself by stepping into framework
code. See the article below for an example on how to configure Visual Studio
2008 to enable this

http://blogs.msdn.com/sburke/archive...urce-code.aspx

--
Happy Coding!
Morten Wennevik [C# MVP]
"Tony" wrote:
Hello!!

I just wonder does this OnInsert(...)
actually do anything when I'm not overriding it.

//Tony

"Morten Wennevik [C# MVP]" <Mo************ @hotmail.comskr ev i meddelandet
news:2B******** *************** ***********@mic rosoft.com...

"Tony" wrote:
Hello!
>
Will it be some performance effect if a use List insted of InnerList
when
not having any OnInsert(...)
>
//Tony
>
There is a tiny overhead when using List vs InnerList, but it is only
visible when using large collections (>1 000 000 items) and even then
measurable in milliseconds. Most likely this wouldn't be the bottleneck
in
performance issues even then. If you need to override
CollectionBase-behaviour, use List, if you don't, or if you want to
circumvent overridden behaviour, use InnerList.

--
Happy Coding!
Morten Wennevik [C# MVP]



Jun 27 '08 #6

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

Similar topics

4
1799
by: Majed | last post by:
hi all i've created a strong named collection which inherits collection base,but when i try to add to it a nullreferenceexception blows. the code is as listed below. do i have to init the list myself. any hints...please! thanks all Public Class NewKeys Inherits BaseCollection
2
10769
by: Colin Basterfield | last post by:
Hi, I have a list which is derived from CollectionBase, and it contains a list of User objects, which I want to Serialize out to an XML file. Is there anywhere where I can find how to decode it so that it recognizes what objects are held in my list? or an example in C# prefereably? Many thanks in advance... Colin
3
4582
by: jason | last post by:
Hello. I've got this simple collection populate code I downloaded from the net (sorry can't find source now) I'm trying to test, but I can't seem to get it to work. Any help would be greatly appreciated. I've compiled the following VB.NET into a DLL: Imports System Imports System.Data Imports System.Data.SqlClient Imports System.Collections
3
2117
by: moondaddy | last post by:
I wrote my own List class which I use to bind to list controls. this class inherits CollectionBase and implements IBindingList. This class contains a list of business classes such as customers for example. In the customer class I have an event called MyTestEvent and when certain conditions arise, I want to raise this event which would cause an event to fire in the List class. How can this be done when I don't actually declare the...
9
2019
by: me | last post by:
Hi All, I am new to Classes and learniing the ropes with VB.NET express Here's my question - say I have a want to manage a list of books. Each book has an Author, Title and ISBN Now, I am used to using Arrays so I would normally do something like this: Set an array up during the init routine (called from form_load) say of
8
3926
by: Yuk Tang | last post by:
I am tearing my hair out over this, since I can't see what I'm doing wrong (duh, if I knew, I wouldn't be asking the question). I am adding Field items to a Field Collection, but for some reason it wants to start from the beginning and overwrite all entries before adding the latest member. I've added a couple of msgboxes to illustrate this, one at the add method, another cycling through the collection after the addition has been made. ...
2
3569
by: Demetri | last post by:
I have a collection class that inherits from CollectionBase. I am using the List.Remove method to remove an object in the collection. When I use it, I get the following error: Exception Details: System.Runtime.Serialization.SerializationException: The type MyEntity in Assembly MyBusiness, Version=1.0.2263.29542, Culture=neutral, PublicKeyToken=null is not marked as serializable. What gives?
2
3409
by: adriaandavel | last post by:
Hi all, I am trying to use a collection of String Arrays in an inherited instance of CollectionBase, but the InnerList.IndexOf does not seem to work, any ideas? My code is: public void Add(string str1, string str2, string str3) {
3
2116
by: Tony Johansson | last post by:
Hello! Sorry for opening up this task again. I want to fully understand this List that is return from CollectionBase. According to you is List in CollectionBase implemented something like the below which you sent me previously. So the referenced type for List that will be returned at execution time must be CollectionBase. The compile type for List
0
9028
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
8895
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
8861
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
7728
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
6518
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
5860
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
4369
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
4619
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3046
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

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.