What is the difference between type and class

  • Thread starter Thread starter ad
  • Start date Start date
A

ad

I am confuse about type and class in some book about C#.
What is the difference between type and class?
 
They are basically the same i guessed.

Also, there is a class called Type in .NET. To get a type from a class
you would go Type t = typeof(ClassName);
 
"Type" is used when we are discussing types. In simple words, you see that
whenever we use variables, they "always" have a type no matter if they are
int, float, string, stringbuilder, FileStream. They are all types, but not
all of them are classes! int is not a class, it is a struct or "value type"
in .net terminology.

Ab.
http://joehacker.blogspot.com
 
The way I see it, a type is anything that can be used to "type" a variable.
And that doesn't always need to be a class. Enumerations, for example, are
not classes but they are types because a variable can be typed as an
enumeration.

In general, the .NET Framework recognizes these types:

- Value types, for example int, bool, and any enumerations and structs you
create in your code.
- Reference types, i.e., classes, interfaces, arrays, and delegates.

Hope this makes sence.
 
ad... it depends on the definition of type. if you define type as a
public interface then a class can have many types. a reference variable
has type and an object has class.

Regards,
Jeff
 
Back
Top