Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
Isn't type refering to an actual object-type? So for example
class Product
Defines the "Product"-Type
Dont know this for sure ;) -
Crost40746yIn c# object is actually a type as well, it's the base type for all primitives.
But then there Type as well...? -
BigBoo23126yIn OOP the object refers to the specific instance of a type.
So for example in Java.
Person p = new Person();
p is the instance of Person.
In other words. p is the object. Person is the type.
We could have multiple person objects.
Person p1 = new Person();
Person p2 = new Person();
Both p1 and p2 are of the Type Person.
But they are not the same instance. -
Crost40746y@BigBoo in c# object is also a type that all primitives inherit from.
I think the type 'Type' is a classification in that every type is a type but primitives don't inherit from it, they are Types.
Unsure. -
BigBoo23126y@craig939393 Both in C# and Java there is a class called Object aswell. So yes. An object can be of the type Object.
However if you don't make distinctions between the type Object and the concept of objects. You are just going to get confused.
It all makes sense when you get fluent with inheritance and interfaces. But it's not going to hinder you a lot as a developer if you don't get it at first. -
BigBoo23126y@craig939393 I'm not sure about your wording or what you mean.
But in C# primitives are Objects aswell.
But in Java we have boxed types which are immutable objects.
For example Integer is the boxed type of int.
Integer can be instanced into an object.
int can not be instanced into an object.
I hope I'm answering your question lol. -
Crost40746y@BigBoo yeah I'm not really talking about object instantiation, but I appreciate your answer anyway.
Cheers -
BigBoo23126y@craig939393
It's all semantics, and you probably don't have to sweat it if you don't get it directly. Just let it sit and think about it for a while. Maybe you will get an AHAAAA moment later lol 😀 -
object is a type (note the lowercase)
Type (note the uppercase) is a type.
In a variable with a Type type you can store types like this:
var someVar = 1;
Type varType = typeof(someVar);
Could be wrong with the type retrieval of an object because I normally dont do it like this (but easier for explanations)
What can this be used for? Lets say you have a variable of type IAnimal. This variable can store things that implement IAnimal. For example an instance of a Dog or Cat class.
Using the Type you can differentiate the two things later on in your code. -
@jschmold to be honest your explanation is less clear.
type is not a class, Type is.
But Type and int are both types -
@jschmold you are saying the same thing but im explaining the difference between Type and type where you just mix the two again to make it less clear...
-
@jschmold just what I say: var b = 2
Then the type of b is int.
And with Type im really referencing the class.
Related Rants
Any C# Devs around that could tell me what the difference between Type and object is please? I'm really stuck for googling it.
question
c#