Re: Is Class Synonymous with Type?



Nice one. Thanks


Peter

"Kevin Spencer" <spam@xxxxxxx> wrote in message
news:O%23DPngIGHHA.3952@xxxxxxxxxxxxxxxxxxxxxxx
So-called "Native Types" (int, double, struct, enum, etc) ARE classes,
which inherit System.ValueType, which inherits System.Object. See:

http://msdn2.microsoft.com/en-gb/library/aa904377(VS.71).aspx
http://msdn2.microsoft.com/en-gb/library/system.valuetype(VS.71).aspx

ALL types are classes. And all classes are types.

And in this respect, C# (and more importantly, the CLI) is COMPLETELY OO.

--
HTH,

Kevin Spencer
Microsoft MVP
Logostician
http://unclechutney.blogspot.com

There is a madness to my method.

"Peter Bradley" <pbradley@xxxxxxxxxx> wrote in message
news:uECvC9HGHHA.1064@xxxxxxxxxxxxxxxxxxxxxxx
Remember not all types are classes. Native types are just that. Native
types. They are not classes (unless they've been converted into special
classes, by boxing for example). They are ints, floats, doubles, bytes
etc etc. - and nothing else.

Similarly Structs are not classes. They are structs. Structs are
another type of type: user defined value types, as it happens. As
someone else has pointed out, there are also enumeration types, delegate
types, interface types, even Type types.

In this respect, C# is not completely OO. For that you have to look at
something like Smalltalk, where everything is a class (or a meta class) -
or an object, of course. Java sort of goes part way by defining classes
that encapsulate the native types. C# does something similar with
boxing.

Remember, a type, when instantiated, is just a bit of memory defined
either by a reference (pointer) for reference types, or a label for value
types.

Languages do not have to be OO to have types. C is not OO and has types.
The type is what you put before a variable when you declare it:

int i;
float f;
char* s;

The above declare three variables in C of type int, float and pointer to
char respectively.

You do pretty much the same sort of thing in C#:

int i;
float f;
string s;

Post again if you're still confused.


HTH


Peter


The same goes for Enums, Delegates and all the other things that have
been mentioned.
<garyusenet@xxxxxxxxx> wrote in message
news:1165330225.345564.99600@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Thankyou all very much. It is quite a lot clearer now thankyou.

One question though. At the moment (i hope i haven't misunderstood) My
understanding is that all types are ultimately defined in a class.
'native types' already have their classes defined, and user types are
defined by individual users in new classes.

But it was said in this thread that a class, is a type of type.

So i guess my understanding must still be a bit flawed, for if a type
is defined by a class, and a class is a type of type, the class type
would have to be defined in a class and we would have an infinite
amount of classes each defining each other.

Can someone clarify this for me please?

Thankyou







.



Relevant Pages