473,625 Members | 3,239 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Strange problem withCollectionB ase

Hello!

Assume I have this inheritance see below.
I know that a much better alternative is to use generics but I just want to
know how things works.

According to the documentation in CollectionBase for member List it return
an IList.
In the class Int16Collection I check by using method Test what this List in
CollectionBase is actually refering to and
it's refering to Int16Collection .
So according to that and the documenation we should have this kind of
situation.
IList List = refering to my instance of Int16Collection which is the same as
the keyword this.

So because this List is actually refering to an instance of Int16Collection
I should be able to use intellisense on this List which should display Foo
as a possible member to use but
as a matter of fact it doesn't if I cast to Int16Collection this Foo is
available.

But I can't understand this if List is actually refering to an instance to
Int16Collection
this Foo should be display when the intellisense is used on List.

public class Int16Collection : CollectionBase
{
public void Test()
{
Console.Writeln (List.GetType() ); //It writes out Int16Collection
}

public void Foo()
{

}
}

I would be very glad is someone can explain this to me ?

//Tony

Jun 29 '08 #1
6 1080
Tony Johansson <jo************ *****@telia.com wrote:
Assume I have this inheritance see below.
I know that a much better alternative is to use generics but I just want to
know how things works.

According to the documentation in CollectionBase for member List it return
an IList.
In the class Int16Collection I check by using method Test what this List in
CollectionBase is actually refering to and
it's refering to Int16Collection .
The List property of CollectionBase always returns "this" (i.e. the
same instance).
But I can't understand this if List is actually refering to an instance to
Int16Collection
this Foo should be display when the intellisense is used on List.
No, because the *compile-time* type of the List property is "IList".
Intellisense is based on the knowledge at compile-time.

Here's another example:

object o = "Hello"
int i = o.Length;

That won't compile, because even though o actually refers to a string
at execution time, the compiler only know that it's of type "object"
which doesn't have a Length property.

--
Jon Skeet - <sk***@pobox.co m>
Web site: http://www.pobox.com/~skeet
Blog: http://www.msmvps.com/jon_skeet
C# in Depth: http://csharpindepth.com
Jun 29 '08 #2
Hello!!

If I have the construction below and I check the type for List by using the
CheckTypeOnList method
this methods WriteLine will display Int16Collection so here it must mean
that List is refering to class Int16Collection .
But according to you it should return *this* which is CollectionBase.
Have I missed something here when you wrote
The List property of CollectionBase always returns "this" (i.e. the
same instance).


public class Int16Collection : CollectionBase
{
public CheckTypeOnList ()
{
Console.Wroteln (List.GetType() );
}

}
//Tony

"Jon Skeet [C# MVP]" <sk***@pobox.co mskrev i meddelandet
news:MP******** *************@m snews.microsoft .com...
Tony Johansson <jo************ *****@telia.com wrote:
>Assume I have this inheritance see below.
I know that a much better alternative is to use generics but I just want
to
know how things works.

According to the documentation in CollectionBase for member List it
return
an IList.
In the class Int16Collection I check by using method Test what this List
in
CollectionBa se is actually refering to and
it's refering to Int16Collection .

The List property of CollectionBase always returns "this" (i.e. the
same instance).
>But I can't understand this if List is actually refering to an instance
to
Int16Collectio n
this Foo should be display when the intellisense is used on List.

No, because the *compile-time* type of the List property is "IList".
Intellisense is based on the knowledge at compile-time.

Here's another example:

object o = "Hello"
int i = o.Length;

That won't compile, because even though o actually refers to a string
at execution time, the compiler only know that it's of type "object"
which doesn't have a Length property.

--
Jon Skeet - <sk***@pobox.co m>
Web site: http://www.pobox.com/~skeet
Blog: http://www.msmvps.com/jon_skeet
C# in Depth: http://csharpindepth.com

Jun 29 '08 #3
Tony Johansson <jo************ *****@telia.com wrote:
If I have the construction below and I check the type for List by using the
CheckTypeOnList method
this methods WriteLine will display Int16Collection so here it must mean
that List is refering to class Int16Collection .
That's the execution-time type.
But according to you it should return *this* which is CollectionBase.
No, because you're calling it on Int16Collection . Change your code to

Console.WriteLi ne(this.GetType ())

and you'll see Int16Collection as well.

--
Jon Skeet - <sk***@pobox.co m>
Web site: http://www.pobox.com/~skeet
Blog: http://www.msmvps.com/jon_skeet
C# in Depth: http://csharpindepth.com
Jun 29 '08 #4
Hello!

Have I misunderstood this.
If I use List.GetType it must mean that what is List refering to at
execution type and here
I get Int16Collection as an answer.
Is that correct?

So in that case what do you mean with this "The List property of
CollectionBase always returns "this" (i.e. the
same instance)." ?

public class Int16Collection : CollectionBase
{
public CheckTypeOnList ()
{
Console.Wroteln (List.GetType() );
}
}
//Tony
"Jon Skeet [C# MVP]" <sk***@pobox.co mskrev i meddelandet
news:MP******** *************@m snews.microsoft .com...
Tony Johansson <jo************ *****@telia.com wrote:
>If I have the construction below and I check the type for List by using
the
CheckTypeOnLis t method
this methods WriteLine will display Int16Collection so here it must mean
that List is refering to class Int16Collection .

That's the execution-time type.
>But according to you it should return *this* which is CollectionBase.

No, because you're calling it on Int16Collection . Change your code to

Console.WriteLi ne(this.GetType ())

and you'll see Int16Collection as well.

--
Jon Skeet - <sk***@pobox.co m>
Web site: http://www.pobox.com/~skeet
Blog: http://www.msmvps.com/jon_skeet
C# in Depth: http://csharpindepth.com

Jun 29 '08 #5
Tony Johansson <jo************ *****@telia.com wrote:
Have I misunderstood this.
If I use List.GetType it must mean that what is List refering to at
execution type and here
I get Int16Collection as an answer.
Is that correct?
Yes.
So in that case what do you mean with this "The List property of
CollectionBase always returns "this" (i.e. the
same instance)." ?
I mean that the List property is implemented as:

protected IList List
{
get
{
return this;
}
}

--
Jon Skeet - <sk***@pobox.co m>
Web site: http://www.pobox.com/~skeet
Blog: http://www.msmvps.com/jon_skeet
C# in Depth: http://csharpindepth.com
Jun 29 '08 #6
Hello!

This may seem contradiction for me!

According to you is List in CollectionBase implemented something like the
below which you sent me. So the referenced type for List that will be
returned at execution time must be CollectionBase. The compile type for List
is IList
But when I looked at it by using method Test in Int16Collection (see below) I
get that the referenced type at execution type is Int16Collection .
So the referenced type from CollectionBase for List is not the same as the
referenced type for List when I use GetType in method Test.
What is it that I miss here ?

< protected IList List
{
get
{
return this;
}
}
public class Int16Collection : CollectionBase
{
public void Test()
{
Console.Writeln (List.GetType() ); //It writes out Int16Collection
}
}

//Tony
"Jon Skeet [C# MVP]" <sk***@pobox.co mskrev i meddelandet
news:MP******** *************@m snews.microsoft .com...
Tony Johansson <jo************ *****@telia.com wrote:
Have I misunderstood this.
If I use List.GetType it must mean that what is List refering to at
execution type and here
I get Int16Collection as an answer.
Is that correct?

Yes.
So in that case what do you mean with this "The List property of
CollectionBase always returns "this" (i.e. the
same instance)." ?

I mean that the List property is implemented as:

protected IList List
{
get
{
return this;
}
}

--
Jon Skeet - <sk***@pobox.co m>
Web site: http://www.pobox.com/~skeet
Blog: http://www.msmvps.com/jon_skeet
C# in Depth: http://csharpindepth.com

Jun 30 '08 #7

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

Similar topics

2
1809
by: Arthur | last post by:
I've come across some strange xml, that I need to deal with, it looks like this:- <root> <foo attr="1">Some random strange text. <bar attr="2">blar</bar> <bar attr="3">blar blar</bar> <bar attr="4">blar blar blar</bar> </foo> </root>
2
1960
by: Paul Drummond | last post by:
Hi all, I am developing software for Linux Redhat9 and I have noticed some very strange behaviour when throwing exceptions within a shared library. All our exceptions are derived from std::exception. We have a base class which all processes derive from which is always instantiated in main surrounded by a try/catch(std::exception) which catches all exceptions that have not be handled at a higher level. The catch block cleans up and...
2
8916
by: Olaf | last post by:
I have a frameset page witch contains the myFuc() function. The function is accessed from a page in one of the frames in the frameset. An example is shown below. <input onclick="javaScript:alert('document.forms(0)='+document.forms(0)); parent.myFunc(document.forms(0));" type="button" value="Open" name="Button" ID="Button"> The strange part is that the debug alert says that the document.forms(0) is an object så all seem to be well. But...
7
1657
by: M O J O | last post by:
Hi, I'm developing a asp.net application and ran into a strange css problem. I want all my links to have a dashed underline and when they are hovered, it must change to a solid line. Sounds simple, but it's not working. I've cooked down my output code to show you what I mean. If you run the code below, there's no line under the link, but if you either remove the
25
3716
by: Neil Ginsberg | last post by:
I have a strange situation with my Access 2000 database. I have code in the database which has worked fine for years, and now all of a sudden doesn't work fine on one or two of my client's machines. The code opens MS Word through Automation and then opens a particular Word doc. It's still working fine on most machines; but on one or two of them, the user is getting an Automation Error. The code used is as follows: Dim objWord As...
0
1105
by: unknown | last post by:
Hi, I am developing an online book store with shopping cart. My shopping cart is represented as a Xml server control and I am using an XSLT to render it at the client side. I am using an XmlDocument object as session variable to represent my shopping cart. Initially when the session starts, I am using the XmlDocument with root and no elements to show that no items have been added to the
0
328
by: Kris Vanherck | last post by:
yesterday i started getting this strange error when i try to run my asp.net project: Compiler Error Message: CS0006: Metadata file 'c:\winnt\microsoft.net\framework\v1.1.4322\temporary asp.net files\spsweb\0e3514bf\cb1844e7\assembly\dl2\3b163f 16\00452d31_84e5c301\infragistics.webui.ultrawebgrid.v3.dll' could not be found
11
2583
by: Martin Joergensen | last post by:
Hi, I've encountered a really, *really*, REALLY strange error :-) I have a for-loop and after 8 runs I get strange results...... I mean: A really strange result.... I'm calculating temperatures. T = 20 degrees at all times.... The 2D T-array looks like this:
20
1665
by: SpreadTooThin | last post by:
I have a list and I need to do a custom sort on it... for example: a = #Although not necessarily in order def cmp(i,j): #to be defined in this thread. a.sort(cmp) print a
14
3313
by: blumen | last post by:
Hi all, I'm a newbie in VB.Net Programming.. Hope that some of you can help me to solve this.. I'm working out to read,parse and save textfile into SQL Server. The textfile contains thousands of rows with about 50 coloums every row.. Everythings goes well until I found one textfile with some strange character...seems to be Japanese character(because it's a Japanese company who owns this textfile)
0
8637
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
8358
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
8502
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...
1
6119
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
5571
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
4195
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2621
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
1
1805
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1504
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.