Results 1 to 9 of 9

Thread: [RESOLVED] [2.0] what is "Type" means?

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2003
    Posts
    436

    Resolved [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

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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:
    1. Dim s As String
    2. 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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2.0] what is "Type" means?

    Sorry. Forgot I was in C# land. That code translates to:
    Code:
    string s;
    int i;
    There is no 'As' key word in C# so the equivalent is anything you can put before an identifier in a variable declaration.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2003
    Posts
    436

    Lightbulb 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

  6. #6

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2003
    Posts
    436

    Unhappy 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

  7. #7
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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:
    1. Dim typ1 As Type = GetType(String)
    2.  
    3. Dim str As String = "Hello World"
    4. 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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  8. #8
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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();
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  9. #9

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2003
    Posts
    436

    Smile 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
  •  



Click Here to Expand Forum to Full Width