|
-
Apr 23rd, 2006, 05:41 PM
#1
Thread Starter
Hyperactive Member
[RESOLVED] [2.0] what is "Type" means?
The concept of "Type" is very confusing to me.
Can some one explain or point to me for some articles on this?
thanks
nath
Last edited by Hack; Apr 24th, 2006 at 07:33 AM.
Reason: Added [RESOLVED] to thread title and green "resolved" checkmark
-
Apr 23rd, 2006, 06:10 PM
#2
Re: [2.0] what is "Type" means?
What is the type of the car you drive (if you're old enough)? What is the type of the computer you use? What is the type of an object in your program? The type of something is the kind of object it is. Anything you can put after the 'As' key word is a type, e.g.
VB Code:
Dim s As String
Dim i As Integer
String and Integer are both types. Every class, structure, delegate, enumeration, etc. is a type. Each object you create in your program is an instance of a type.
-
Apr 23rd, 2006, 06:14 PM
#3
Re: [2.0] what is "Type" means?
Sorry. Forgot I was in C# land. That code translates to:There is no 'As' key word in C# so the equivalent is anything you can put before an identifier in a variable declaration.
-
Apr 23rd, 2006, 07:43 PM
#4
Re: What is the relationship between "Type" and "Object"
In C# and all OO languages "object" is the general term used to describe a self-contained entity. Bascially every variable in OOP is or refers to an object. In the .NET Framework "Object" (upper case 'O') is also the base class that all other types derive from. Every object is an instance of the Object class. In short, an object is a thing and a type is a classification of things. The type is a template for objects that are instances of that type. In the real world, you know what a Car is. It has four wheels, an engine, etc. Car is a type that describes what cars are: what they have and what they do. Each car on the road is an object: an instance of the Car type.
Note that while they have specific definitions in programming the words "type" and "object" are used pretty much as they are in the real world. Objects are entities: things that you can hold, use, etc. There are different types of objects in the real world. E.g. I could ask "what type of car do you drive?" and you would answer with a make and model. That make and model is a type and every one of those on the road is an object: an instance of that type.
-
Apr 23rd, 2006, 08:50 PM
#5
Thread Starter
Hyperactive Member
Re: What is the relationship between "Type" and "Object"
Wow...
Deep explanation. I just took print out of your reply and I am trying to relate your explanation to the examples in MSDN (Type and Object examples)...
thanks
regards
nath
-
Apr 23rd, 2006, 09:01 PM
#6
Thread Starter
Hyperactive Member
Re: What is the relationship between "Type" and "Object"
Jm,
Code:
Employee nathreddy = new Employee(); //employee is a class
Type abc = nathreddy.GetType();
Here I understand that we are trying to get the Type of "nathreddy" object (which is an instance of class Employee).
Why are we assigning to abc variable which is of "Type" . Is Type a class here?
thanks
nath
-
Apr 23rd, 2006, 09:08 PM
#7
Re: What is the relationship between "Type" and "Object"
Note that "type" and "object" are general OOP terms. The .NET Framework has an Object class, which all other types derive from and which every object is an instance of. There is also a Type class. There is an instance of the Type class for every type and it allows you to use reflection to get information about the type it represents. You get an instance of the Type class from either an object or a type using GetType:
VB Code:
Dim typ1 As Type = GetType(String)
Dim str As String = "Hello World"
Dim typ2 As Type = str.GetType()
You can then use that Type instance to get information about the type through reflection, like what methods and properties it has. If the first letter is upper case (Object, Type) then you're talking about the class of that name. If the first letter is lower case (object, type) then you're using the general OOP term.
-
Apr 23rd, 2006, 09:10 PM
#8
Re: What is the relationship between "Type" and "Object"
Bah! Forgot this was C# land... AGAIN!
Code:
Type typ1 = typeof(string);
string str = "Hello World";
Type typ2 = str.GetType();
-
Apr 23rd, 2006, 10:13 PM
#9
Thread Starter
Hyperactive Member
Re: What is the relationship between "Type" and "Object"
jm,
You are my Guru....
I mean C# GURU...
Regards
nath....
beginners like me need people like to understand and develop stable and maintainable applications....
thanks
regards
nath
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|