Type versus Class

  • Thread starter Thread starter Mark
  • Start date Start date
M

Mark

I always use the word "class" to describe a class that can be instantiated.
However, I don't get the concept of "Type" or at least I don't know how to
use the word properly. If I have a class called Person, what is its "Type"
and how does it relate to the class?

Thanks in advance.

mark
 
Mostly, "class" refers particularly to references types, while "type"
refers to both Reference Types, and Value Types
 
So this means I could just as well talk about my "Person type", and just
chuck my previous wording of "Person class?" I'm hoping there is a more
precise difference between the two ...

Thanks again.

Mark
 
A class is a template that defines the members and operations of a
type.

....if that helps! :)

P.
 
Just out of curiosity, I looked it up in that MSDN glossary:

class
A reference type that encapsulates data (constants and fields) and behavior
(methods, properties, indexers, events, operators, instance constructors,
static constructors, and destructors), and can contain nested types. Class
types support inheritance, a mechanism whereby a derived class can extend
and specialize a base class.

common type system
The specification that determines how the common language runtime defines,
uses, and manages types.

Using the System.Reflection namespace yields a greater appreciation of where
Class ends and Type begins..but to answer your question most use the
phrasing "Person Class" and "Type of Person" interchangeably.

ok,
aq
 
Paul E Collins said:
A class is a template that defines the members and operations of a
type.

...if that helps! :)

I'm not sure it does, because that describes a struct as well.

To my mind, it's as James described it - class is used for most
reference types (other than delegates, which are just called delegates)
whereas enums and structs are also types.
 
There are of course different definitions of a type. If you define a
type as a defined public interface then a class can have zero or more
types. For instance, a class can inherit from Object and implement
IDisposable then the class defines at least two specific public
interfaces, Object and IDisposable.

Class MyClass : Object, IDisposable;
MyClass c= new MyClass(); // object of class MyClass,
// reference var c of type MyClass
Object o= new MyClass(); // object of class MyClass
// ref variable o of type object
IDisposable d= new MyClass(); // object of class MyClass
// ref var d of type IDisposable


Regards,
Jeff
 
You may get it this way...

You can have a class called Person, and if you create a new object of type
Person called lobjPerson... you can say that lobjPerson is a object of type
Person.

Regards,
Nirosh.
 
Mark said:
I always use the word "class" to describe a class that can be instantiated.
However, I don't get the concept of "Type" or at least I don't know how to
use the word properly. If I have a class called Person, what is its
"Type"
and how does it relate to the class?

It's fairly simple. a class and a struct are both types.
As a chair and a table are both furniture.
 
Mark said:
I always use the word "class" to describe a class that can be instantiated.
However, I don't get the concept of "Type" or at least I don't know how to
use the word properly. If I have a class called Person, what is its "Type"
and how does it relate to the class?

Thanks in advance.

mark

In some sense, class is just a more complicated type.

Think of struct as something in between.

You can instantiate an Integer() type just as well as any other "class"
-- it's just the class type has both properties and methods.

The idea of a type is a formatted structure.

We speak of /primitive/ types, int, string and so on.
 
Ricola ! said:
In some sense, class is just a more complicated type.

Think of struct as something in between.

In between what?
You can instantiate an Integer() type just as well as any other "class"
-- it's just the class type has both properties and methods.

Structs can have properties and methods too.
The idea of a type is a formatted structure.

.... with associated behaviour.
We speak of /primitive/ types, int, string and so on.

Actually, string isn't a primitive type.
 
Type can be understood as a template - in real .Net terms, type is an
abstract class that is capable of encapsulating any class' information
i.e. it can represent a type and can be used to reflect on that class. A
class is a functional entity whereas, a type represents that
functionality.

with regards,


J.V.Ravichandran
- http://www.geocities.com/
jvravichandran
- http://www.411asp.net/func/search?
qry=Ravichandran+J.V.&cob=aspnetpro
- http://www.southasianoutlook.com
- http://www.MSDNAA.Net
- http://www.csharphelp.com
- http://www.poetry.com/Publications/
display.asp?ID=P3966388&BN=999&PN=2
- Or, just search on "J.V.Ravichandran"
at http://www.Google.com
 
This may help

Categories of types
Types can be classified with following categories:

primitive types - simplest kind of type e.g. integer and floating-point
number
composite types - types consisting of basic types e.g. abstract data
types
subtype and derived type
function types e.g. binary functions
object types e.g. type variable
class types i.e. type of an object
interfaces i.e. type of a dependency
protocols i.e. type of a communication channel
kinds i.e. type of a type

Regards,
Jeff
 
Back
Top