I don't quite understand why this code works... simple, but I just don't get it.

I don't understand why you can cast a CurrencyManager as a DataView.

int rowCount = (currManager as DataView).Count;

I don't see how that works, but it does. I know this is really simple, but looking at the class heirarchy for these objects, it just doesn't make sense to me.
LVL 6
PoeticAudioAsked:
Who is Participating?
 
gbzhhuConnect With a Mentor Commented:

From MSDN

<quote>
The object returned by the List property can be cast to any type that implements the IList interface. This will be commonly used when you know the type of the underlying list. For example, if you are data-bound to a DataSet, the underlying list is a DataView (which implements IList). Other classes that implement the interface (this is not a complete list) include Array, ArrayList, and CollectionBase.
</quote>

DataView implements IList as stated above, therefore the Count property is accessible

The wonders of Interfaces ;-)

0
 
PoeticAudioAuthor Commented:
WAIT, MADE A MISTAKE...

It's the CurrencyManager.List that casts, but I still don't get it.

int rowCount = (currManager.List as DataView).Count;
0
 
pallospCommented:
I neither understand why it works for you.

I get a compile-time error in Visual Studio 2005:
Cannot convert type 'System.Windows.Forms.CurrencyManager' to 'System.Data.DataView' via a built-in conversion
0
 
PoeticAudioAuthor Commented:
read my second post
0
 
PoeticAudioAuthor Commented:
ahh. Okay. Thanks man!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.