C
C#โ€ข2y ago
Soinagie

โ” what's an object?

Can somebody please explain to me in very simple words what's an obkect as I don't understand it from explanations on the internet
740 Replies
Angius
Angiusโ€ข2y ago
It's a thing A car is an object A desk is an object The chair you're sitting on is an object It's not any different when it comes to programming
Soinagie
SoinagieOPโ€ข2y ago
So it's just a variable?
Angius
Angiusโ€ข2y ago
No
Soinagie
SoinagieOPโ€ข2y ago
Like x=10?
Angius
Angiusโ€ข2y ago
A variable is the object's address, you could say
Soinagie
SoinagieOPโ€ข2y ago
What address
Angius
Angiusโ€ข2y ago
How you refer to that specific object Like, you have a Car. But which car do you mean?
Soinagie
SoinagieOPโ€ข2y ago
I still don't know what objects are
Angius
Angiusโ€ข2y ago
var myCar = new Car();
var yourCar = new Car();
var myCar = new Car();
var yourCar = new Car();
Soinagie
SoinagieOPโ€ข2y ago
So Im not sure I understand
Angius
Angiusโ€ข2y ago
Two different objects, two different cars So each has a different name There's my car, and there's your car
Soinagie
SoinagieOPโ€ข2y ago
And they're both new cars?
Angius
Angiusโ€ข2y ago
They're both cars
Soinagie
SoinagieOPโ€ข2y ago
New cars
Angius
Angiusโ€ข2y ago
new is how you instantiate an object in C#
Soinagie
SoinagieOPโ€ข2y ago
What
Angius
Angiusโ€ข2y ago
How you create a new instance of a car A new instance of an object
Soinagie
SoinagieOPโ€ข2y ago
Idk even know what instantiate means๐Ÿ˜ญ
Angius
Angiusโ€ข2y ago
To create an instance of An individual thing A class, in C#, is sort of a blueprint for a thing. A concept of it, an idea of it Then, from that class, you can create a specific instance
Soinagie
SoinagieOPโ€ข2y ago
Why make new instance of a car?
Angius
Angiusโ€ข2y ago
A specific, existing, physical object Because you want an actual car Not just an idea of a car
Soinagie
SoinagieOPโ€ข2y ago
You already have it just copy it
Angius
Angiusโ€ข2y ago
What if both have different colors?
Soinagie
SoinagieOPโ€ข2y ago
But you didn't write that anywhere
Angius
Angiusโ€ข2y ago
var myCar = new Car("Ford", "Blue");
var yourCar = new Car("Mazda", "Green");
var myCar = new Car("Ford", "Blue");
var yourCar = new Car("Mazda", "Green");
Soinagie
SoinagieOPโ€ข2y ago
Im confused
Angius
Angiusโ€ข2y ago
And even in the case of
var myCar = new Car();
var yourCar = new Car();
var myCar = new Car();
var yourCar = new Car();
what if I want to start just a specific car?
myCar.Start();
myCar.Start();
I don't want to start the idea of a car I want to start specifically my own car
Soinagie
SoinagieOPโ€ข2y ago
What idea?
Pobiega
Pobiegaโ€ข2y ago
Are two black fords the same car? no, they are two different instances of a black ford
Angius
Angiusโ€ข2y ago
The idea of a thing, the concept of it, not the specific given thing
Soinagie
SoinagieOPโ€ข2y ago
What?
Angius
Angiusโ€ข2y ago
"A chair" is a general term, a name for the concept of this piece of furniture "A chair" doesn't have colour or shape "The chair" does When I say "chair" it doesn't have colour When I say "my chair" or "your chair" or "that chair over there", they do They're no longer abstract concepts, they're concrete, existing, physical objects
Soinagie
SoinagieOPโ€ข2y ago
But only if you put that color in parentheses
Angius
Angiusโ€ข2y ago
That's a constructor You can just... not have a constructor, and it can still work
Soinagie
SoinagieOPโ€ข2y ago
Sorry I have no idea about the wording and in general Im just lost
Angius
Angiusโ€ข2y ago
var myCar = new Car();
var yourCar = new Car();

myCar.Color = "Red";
yourCar.Color = "White";
var myCar = new Car();
var yourCar = new Car();

myCar.Color = "Red";
yourCar.Color = "White";
Here, I just set the colour of those cars after creating them
Soinagie
SoinagieOPโ€ข2y ago
You just called myCar a variable Then isnt it a variable?
Angius
Angiusโ€ข2y ago
The variable gives that object a name
Soinagie
SoinagieOPโ€ข2y ago
So objects are variables
Angius
Angiusโ€ข2y ago
var Soinahie = new Person();
var Soinahie = new Person();
No Are you your name? Or are you a person, that has a name we can all use to refer to you?
var Pobiega = new Person();
var Pobiega = new Person();
Two different people, with two different names
Soinagie
SoinagieOPโ€ข2y ago
What pobiega?
Angius
Angiusโ€ข2y ago
@Pobiega Another user
Pobiega
Pobiegaโ€ข2y ago
๐Ÿ‘‹
Soinagie
SoinagieOPโ€ข2y ago
I dont understand
Angius
Angiusโ€ข2y ago
You don't understand a difference between a person and their name? We use names if we want to refer to specific people
Soinagie
SoinagieOPโ€ข2y ago
But what about my name?
Pobiega
Pobiegaโ€ข2y ago
What about it?
Angius
Angiusโ€ข2y ago
It's how others can tell you apart from other people? It's how others can refer to you?
Soinagie
SoinagieOPโ€ข2y ago
So its indetificator for an object?
Angius
Angiusโ€ข2y ago
Yep
Pobiega
Pobiegaโ€ข2y ago
in programming we say that "a variable points to an object"
Soinagie
SoinagieOPโ€ข2y ago
And its a variable
Pobiega
Pobiegaโ€ข2y ago
no its two different things. One points to the other
Soinagie
SoinagieOPโ€ข2y ago
They just used var
Pobiega
Pobiegaโ€ข2y ago
a name points to a person var variableName = new Person(); var variableName is indeed a variable but new Person() is not
Soinagie
SoinagieOPโ€ข2y ago
Yeah so my identuficator is a variable
Pobiega
Pobiegaโ€ข2y ago
yes
Soinagie
SoinagieOPโ€ข2y ago
So my name is var
Pobiega
Pobiegaโ€ข2y ago
no, var is a keyword variableName is the name
Soinagie
SoinagieOPโ€ข2y ago
I meant short for a varaible
Pobiega
Pobiegaโ€ข2y ago
okay, then yes
Soinagie
SoinagieOPโ€ข2y ago
My name is a variable string Or something like that
Pobiega
Pobiegaโ€ข2y ago
Soinagie is a "variable" that points to an object discord user
Soinagie
SoinagieOPโ€ข2y ago
And its identificator for object person But I still don't really know what objects are If its not a value or a method then what is it?
Pobiega
Pobiegaโ€ข2y ago
its not a variable, its not a method. its an object its its own term an object is an instance of a type
Soinagie
SoinagieOPโ€ข2y ago
Type of what?
Pobiega
Pobiegaโ€ข2y ago
a type. string is a type for example
Monsieur Wholesome
Monsieur Wholesomeโ€ข2y ago
Not sure how deep youre into math But in maths you also call letters that act as placeholder for a value" variables" Like x*2, where x is a placeholder for whatever value you want it to be x*2 turns into 2*2 when x = 2 Now you can also do the same for primitives (numbers like int, float, etc.)
int result1 = MultiplyTimesTwo(1); // with this i put the value 1 into the "x" variable
int result2 = MultiplyTimesTwo(5); // with this i put the value 5 into the "x" variable
int result3 = MultiplyTimesTwo(999); // with this i put the value 999 into the "x" variable

int MutipleTimesTwo(int x) // x is a variable and a placeholder for whatever value it might be
{
return x * 2;
}
int result1 = MultiplyTimesTwo(1); // with this i put the value 1 into the "x" variable
int result2 = MultiplyTimesTwo(5); // with this i put the value 5 into the "x" variable
int result3 = MultiplyTimesTwo(999); // with this i put the value 999 into the "x" variable

int MutipleTimesTwo(int x) // x is a variable and a placeholder for whatever value it might be
{
return x * 2;
}
Because the values for primitives are so simple, you can write them as constants / literals in your code just like that (MultiplyTimesTwo(1)) But if you have complex data types like a whole Person, like so
class Person
{
public int Age;
public string FirstName;
public string LastName;
}
class Person
{
public int Age;
public string FirstName;
public string LastName;
}
You cant just hardcode a literal value of that into code when using it This class acts as a group of variables. One instance of Person has an Age, a FirstName, a LastName inside of it. When you want to create a new group for, let's say, me, you'd create 1 instance - 1 object - of this class via
Person wholesomePerson = new Person();
Person wholesomePerson = new Person();
That specific variable wholesomePerson now contains an object of type Person
Pobiega
Pobiegaโ€ข2y ago
int, ยดCar` etc
Soinagie
SoinagieOPโ€ข2y ago
Its a variable
Pobiega
Pobiegaโ€ข2y ago
what is? a type? no
Soinagie
SoinagieOPโ€ข2y ago
String
Pobiega
Pobiegaโ€ข2y ago
no, thats type
Soinagie
SoinagieOPโ€ข2y ago
And objects are types of what then?
Pobiega
Pobiegaโ€ข2y ago
string myString;
string myString;
thats a variable called "myString" and the type is string objects are instances of types
Soinagie
SoinagieOPโ€ข2y ago
What does that mean?
Pobiega
Pobiegaโ€ข2y ago
thats what we just discussed with the cars and chairs
circles.png
circles.pngโ€ข2y ago
objects are not types
Soinagie
SoinagieOPโ€ข2y ago
.
Pobiega
Pobiegaโ€ข2y ago
var myCar = new Car();
var yourCar = new Car();

var thirdCar = myCar;
var myCar = new Car();
var yourCar = new Car();

var thirdCar = myCar;
here, we have 3 variables, but only 2 objects thirdCar and myCar both point to the same car
Soinagie
SoinagieOPโ€ข2y ago
I very much appriciate your help but I doubt I'll understand any of this
circles.png
circles.pngโ€ข2y ago
objects are instances of types
Soinagie
SoinagieOPโ€ข2y ago
Why is thirdCar treated like an object?
Pobiega
Pobiegaโ€ข2y ago
what do you mean by that its not?
Soinagie
SoinagieOPโ€ข2y ago
Its just a copy of myCar
Pobiega
Pobiegaโ€ข2y ago
no, its not a copy
circles.png
circles.pngโ€ข2y ago
it is not a copy
Soinagie
SoinagieOPโ€ข2y ago
Its the same
Pobiega
Pobiegaโ€ข2y ago
its a new variable, pointing to the same car
circles.png
circles.pngโ€ข2y ago
pointing = meaning third car is another name for my car
Soinagie
SoinagieOPโ€ข2y ago
There is only newCar and all of these variables refer to it
Angius
Angiusโ€ข2y ago
A person can have multiple names Here, I'm ZZZZZZZZZZZZZZZZZZZ, but my friends refer to me by my actual name And in some games I use other names entirely
Soinagie
SoinagieOPโ€ข2y ago
What does pointing= meaning mean?
circles.png
circles.pngโ€ข2y ago
new <space> Car creates a new car
Pobiega
Pobiegaโ€ข2y ago
okay, lets slow down a bit
var myCar = new Car("black");
var sameCar = myCar;

sameCar.Color = "blue";
Console.WriteLine(myCar.Color);
var myCar = new Car("black");
var sameCar = myCar;

sameCar.Color = "blue";
Console.WriteLine(myCar.Color);
circles.png
circles.pngโ€ข2y ago
both variables mean the same thing
Pobiega
Pobiegaโ€ข2y ago
what do you think this snippet of code will print?
Soinagie
SoinagieOPโ€ข2y ago
There are no "meaning" and "pointing" variables It'll print same car blue?
Pobiega
Pobiegaโ€ข2y ago
Look at the last line of code Console.WriteLine(myCar.Color);
Soinagie
SoinagieOPโ€ข2y ago
Yeah myCar = sameCar So it'll print sameCar With color blue
Pobiega
Pobiegaโ€ข2y ago
you're right, but for the wrong reason :p it will print color blue because myCar is indeed the same car as sameCar but it won't "print sameCar" it will only print the color
MODiX
MODiXโ€ข2y ago
Pobiega#2671
REPL Result: Success
var myCar = new Car("black");
var sameCar = myCar;
sameCar.Color = "blue";
Console.WriteLine(myCar.Color);
public class Car
{
public Car(string color) => Color = color;
public string Color { get; set; }
}
var myCar = new Car("black");
var sameCar = myCar;
sameCar.Color = "blue";
Console.WriteLine(myCar.Color);
public class Car
{
public Car(string color) => Color = color;
public string Color { get; set; }
}
Console Output
blue
blue
Compile: 732.596ms | Execution: 47.060ms | React with โŒ to remove this embed.
Soinagie
SoinagieOPโ€ข2y ago
Why did you put black there? If it isnt used
Pobiega
Pobiegaโ€ข2y ago
to have an initial value
Soinagie
SoinagieOPโ€ข2y ago
Why
Pobiega
Pobiegaโ€ข2y ago
I wanted to demonstrate that they are the same object
Soinagie
SoinagieOPโ€ข2y ago
You give it a value before you print it
Pobiega
Pobiegaโ€ข2y ago
yes
Soinagie
SoinagieOPโ€ข2y ago
And Car and myCar are different things?
Pobiega
Pobiegaโ€ข2y ago
yes, Car is a type, and myCar is a variable what about this code then:
var myCar = new Car("black");
var sameCar = new Car("blue");
sameCar.Color = "red";
Console.WriteLine(myCar.Color);
var myCar = new Car("black");
var sameCar = new Car("blue");
sameCar.Color = "red";
Console.WriteLine(myCar.Color);
Soinagie
SoinagieOPโ€ข2y ago
I thought Car was an object
Pobiega
Pobiegaโ€ข2y ago
no, Car is a type.
Soinagie
SoinagieOPโ€ข2y ago
I wanted to know about objects
Pobiega
Pobiegaโ€ข2y ago
objects are instances of types you create an instance by using the new keyword
Soinagie
SoinagieOPโ€ข2y ago
And I still don't know what that means
Pobiega
Pobiegaโ€ข2y ago
so new Car() creates an object
Akseli
Akseliโ€ข2y ago
object is an instance of a class
Soinagie
SoinagieOPโ€ข2y ago
But newCar is a variable
Pobiega
Pobiegaโ€ข2y ago
yes
Akseli
Akseliโ€ข2y ago
class is a specific blueprint for the objects layout
Soinagie
SoinagieOPโ€ข2y ago
So it isnt an object
Pobiega
Pobiegaโ€ข2y ago
correct. its a variable pointing to an object. so when I say var sameCar = newCar; Im just saying "create a new variable called sameCar that points to the same object as the variable newCar does"
Soinagie
SoinagieOPโ€ข2y ago
It'll print black I guess
Pobiega
Pobiegaโ€ข2y ago
correct.
Soinagie
SoinagieOPโ€ข2y ago
Could you please not use newCar as there already is word "new" being used and it just confuses me
Pobiega
Pobiegaโ€ข2y ago
you're the one who used it I didn't. ^ you created it, I just went with it ๐Ÿ™‚
Soinagie
SoinagieOPโ€ข2y ago
Bc I thought newCar and new Car are thevsame thing
Pobiega
Pobiegaโ€ข2y ago
no ofc not especially not since new Car isnt valid new Car() is the parenthesis is not optional
Soinagie
SoinagieOPโ€ข2y ago
Ok can we take it really slow please?
Pobiega
Pobiegaโ€ข2y ago
sure
Soinagie
SoinagieOPโ€ข2y ago
What is a type?
Pobiega
Pobiegaโ€ข2y ago
You know how computers only actually work with 1s and 0s?
Soinagie
SoinagieOPโ€ข2y ago
Yeah
Pobiega
Pobiegaโ€ข2y ago
well, thats annoying to work with for human programmers but the computer still needs to know how much space of memory (how many 1s and 0s) to reserve for an object
Soinagie
SoinagieOPโ€ข2y ago
What object?
Pobiega
Pobiegaโ€ข2y ago
an object no actual object yet, a theoretical one
Soinagie
SoinagieOPโ€ข2y ago
And what is it?
Akseli
Akseliโ€ข2y ago
are you guys trolling
Soinagie
SoinagieOPโ€ข2y ago
Who?
Akseli
Akseliโ€ข2y ago
an object is an instance of a class
Soinagie
SoinagieOPโ€ข2y ago
And I dont know what instance of a class is
Angius
Angiusโ€ข2y ago
We went through it at the start You need some patience in this case, we're starting from ones and zeroes lol
Pobiega
Pobiegaโ€ข2y ago
types are... well, defined types that the computer knows about, because we told it what they are string, int, or Car in our case
Soinagie
SoinagieOPโ€ข2y ago
Car isnt the same as string and int
Pobiega
Pobiegaโ€ข2y ago
you can make your own, using classes (and other ways, but primarily classes atm) its not the same, but its the same "category" of thing
public class Car
{
public string Color { get; set; }
}
public class Car
{
public string Color { get; set; }
}
Soinagie
SoinagieOPโ€ข2y ago
Sorry idk what get set are
Pobiega
Pobiegaโ€ข2y ago
ignore it
Soinagie
SoinagieOPโ€ข2y ago
I just wanted to learn from the top so I thought I should know what objects are first
Pobiega
Pobiegaโ€ข2y ago
this is a very small type declaration that creates a type called Car that has a property called Color (and type string) sure, but we can't explain objects without introducing other things it doesnt make sense as a stand-alone definition C# is a typed language that means everything has a type
Soinagie
SoinagieOPโ€ข2y ago
So methods have types?
Pobiega
Pobiegaโ€ข2y ago
sure public string GetName() { ... } for example thats a method that returns a string
Soinagie
SoinagieOPโ€ข2y ago
Wait a sec Before we speed off
Akseli
Akseliโ€ข2y ago
no, types have methods but methods can have return types
Soinagie
SoinagieOPโ€ข2y ago
Is getName a method?
Pobiega
Pobiegaโ€ข2y ago
Akseli, you're really not helping at this point So if anyone is trolling, its you.
circles.png
circles.pngโ€ข2y ago
yes
Soinagie
SoinagieOPโ€ข2y ago
Ok so we made a string method
Pobiega
Pobiegaโ€ข2y ago
a method that returns a string, yep
Soinagie
SoinagieOPโ€ข2y ago
Wait
Pobiega
Pobiegaโ€ข2y ago
when we call that method, we know we get something that points to a string back. it can be a new string, or a previously existing string
Soinagie
SoinagieOPโ€ข2y ago
It doesnt say anywhere that it returns
Pobiega
Pobiegaโ€ข2y ago
sure it does. it MUST
Soinagie
SoinagieOPโ€ข2y ago
Or is it implied
Akseli
Akseliโ€ข2y ago
im just making sure no misinformation is fed
Soinagie
SoinagieOPโ€ข2y ago
Since its not a void
Pobiega
Pobiegaโ€ข2y ago
it won't compile if it doesnt return a string
circles.png
circles.pngโ€ข2y ago
the word string, in that position, is the return type
Pobiega
Pobiegaโ€ข2y ago
because we set its return type to string
Soinagie
SoinagieOPโ€ข2y ago
I thought that you had to use "return" keyword For every non-void
Pobiega
Pobiegaโ€ข2y ago
you do
Soinagie
SoinagieOPโ€ข2y ago
And you didn't
Pobiega
Pobiegaโ€ข2y ago
you see how I left out the body of the method with ... as the placeholder?
circles.png
circles.pngโ€ข2y ago
thats in the implementation (code block which is hidden)
Soinagie
SoinagieOPโ€ข2y ago
Im not sure if hiding things for begginers is a good solution but sure
circles.png
circles.pngโ€ข2y ago
for brevity
Pobiega
Pobiegaโ€ข2y ago
well I wanted you to focus on the important part the type in the method signature
Soinagie
SoinagieOPโ€ข2y ago
What signature?
Pobiega
Pobiegaโ€ข2y ago
public string GetName() thats a "method signature"
Soinagie
SoinagieOPโ€ข2y ago
Its a method
Pobiega
Pobiegaโ€ข2y ago
it declares the method it is, but its specifically the signature of the method when you say "method", you often mean the entire thing, including the body
Soinagie
SoinagieOPโ€ข2y ago
Ok so its creation of a method
Pobiega
Pobiegaโ€ข2y ago
yeah
Soinagie
SoinagieOPโ€ข2y ago
and its type is a creation of a method type?
Pobiega
Pobiegaโ€ข2y ago
?
Soinagie
SoinagieOPโ€ข2y ago
Or do you mean string
Pobiega
Pobiegaโ€ข2y ago
its return type is string
Soinagie
SoinagieOPโ€ข2y ago
So this block is creation of a method that'll return a string
Pobiega
Pobiegaโ€ข2y ago
yep and thats important, because we can now know that it wont return an int or a Car it always returns a string.
Soinagie
SoinagieOPโ€ข2y ago
And thats important because?
Pobiega
Pobiegaโ€ข2y ago
imagine you have a method like... public Car GetCar() you know it returns a car, so you write code that uses the returned car then suddenly you decide that GetCar should return int in C#, this will be an error and your code wont compile
Soinagie
SoinagieOPโ€ข2y ago
I mean you can assign numbers to cars
Pobiega
Pobiegaโ€ข2y ago
in a language like javascript, this will be fine, but when you run the program, it will crash sure but thats not what Im saying here, I mean actually returning a number instead of a car
Soinagie
SoinagieOPโ€ข2y ago
But Im getting off track
arion
arionโ€ข2y ago
Yes, u can assign numbers to cars, but a number is not a car. so you can have myCar.CarNumber = 69; It expects a car
circles.png
circles.pngโ€ข2y ago
the returned car has a colour when you have code that expects a car and uses the colour of that car, if you give it an int, it will not work because ints do not have a colour
Soinagie
SoinagieOPโ€ข2y ago
Ok and why did you talk about Car and int not being compatible?
Pobiega
Pobiegaโ€ข2y ago
because you asked why its important that methods have return types
Soinagie
SoinagieOPโ€ข2y ago
I thought that they have to have them
Pobiega
Pobiegaโ€ข2y ago
they do
Soinagie
SoinagieOPโ€ข2y ago
Ok so objects are made up types
Pobiega
Pobiegaโ€ข2y ago
no. its the chair thing again Chair is a type. an object is YOUR chair, or MY chair they are both chairs, but they are different, likely in both color, size and shape but they are both chairs
Soinagie
SoinagieOPโ€ข2y ago
But there is no myInt or yourint
Pobiega
Pobiegaโ€ข2y ago
sure there is
MODiX
MODiXโ€ข2y ago
Pobiega#2671
REPL Result: Success
int myInt = 51;
int myInt = 51;
Compile: 347.904ms | Execution: 58.782ms | React with โŒ to remove this embed.
Pobiega
Pobiegaโ€ข2y ago
I just made one
Soinagie
SoinagieOPโ€ข2y ago
And its an object?
Pobiega
Pobiegaโ€ข2y ago
myInt is a variable myChair was also a variable, technically.
Soinagie
SoinagieOPโ€ข2y ago
It looks like a variable
Pobiega
Pobiegaโ€ข2y ago
a variable POINTING TO AN OBJECT
Soinagie
SoinagieOPโ€ข2y ago
And object being... Where does it point?
Pobiega
Pobiegaโ€ข2y ago
to somewhere in memory
Soinagie
SoinagieOPโ€ข2y ago
What does even that mean?
Pobiega
Pobiegaโ€ข2y ago
new Car() returns a pointer to memory. you store that in a variable and use it
Soinagie
SoinagieOPโ€ข2y ago
So objects are just things you can point towards?
circles.png
circles.pngโ€ข2y ago
so the thing you remember need to be in memory, with an address (where it's located) but idk if you are going that far
ACiDCA7
ACiDCA7โ€ข2y ago
reading through this thread here it sounds like trolling but way to dedicated
Soinagie
SoinagieOPโ€ข2y ago
Wow thanks So motivating
Akseli
Akseliโ€ข2y ago
Car myCar = new Car() new Car() creates a new object of the type Car Car myCar = assign the variable "myCar" which is a reference to point to the new object created
Soinagie
SoinagieOPโ€ข2y ago
Isnt myCar now the same as new Car?
Akseli
Akseliโ€ข2y ago
no
Pobiega
Pobiegaโ€ข2y ago
new Car() isnt a variable new is a reserved keyword used to create objects
Soinagie
SoinagieOPโ€ข2y ago
But you didnt even name it This object Its just a Car
Akseli
Akseliโ€ข2y ago
imagine you have a table with 5 chairs, you know what a chair is, chair is a type, each one of the 5 chairs are objects of the type chair
Pobiega
Pobiegaโ€ข2y ago
objects dont NEED to be in variables to exist, just fyi they dont HAVE to have names. they very often do, but its not a hard requirement
Soinagie
SoinagieOPโ€ข2y ago
I thought they were instances
circles.png
circles.pngโ€ข2y ago
for example objects in a list can have no name but exist
Pobiega
Pobiegaโ€ข2y ago
they are an instance is not the same thing as a variable
Soinagie
SoinagieOPโ€ข2y ago
If they dont have names and variables whats the point of them? All of them are the same Then
Pobiega
Pobiegaโ€ข2y ago
no they are not
circles.png
circles.pngโ€ข2y ago
they might have different properties
Akseli
Akseliโ€ข2y ago
you can have 5 different chairs with different properties like color and size but they are still all chairs
Pobiega
Pobiegaโ€ข2y ago
var list = new List<Car>
{
new Car(),
new Car(),
new Car(),
};
var list = new List<Car>
{
new Car(),
new Car(),
new Car(),
};
Akseli
Akseliโ€ข2y ago
they follow the same blueprint
Soinagie
SoinagieOPโ€ข2y ago
Yeah and they're all different so they should have different names
Pobiega
Pobiegaโ€ข2y ago
"names" isnt a thing
Soinagie
SoinagieOPโ€ข2y ago
So you could separete them
circles.png
circles.pngโ€ข2y ago
do you name your chairs?
Akseli
Akseliโ€ข2y ago
when you give a chair name in real life, the object (the chair) doesnt have a name, you just create a name that means that specific chair
TheRanger
TheRangerโ€ข2y ago
i certainly dont name my chairs ๐Ÿ˜„
Akseli
Akseliโ€ข2y ago
just like variables
Soinagie
SoinagieOPโ€ข2y ago
I mean how will they know which chair am I talking about
Akseli
Akseliโ€ข2y ago
you point to the chair
Soinagie
SoinagieOPโ€ข2y ago
I give them names so other person know which one to pick up
circles.png
circles.pngโ€ข2y ago
"the second chair from the left"
Soinagie
SoinagieOPโ€ข2y ago
And objects are just "second from the left"?
circles.png
circles.pngโ€ข2y ago
which can be "the second item in the list of chairs"
Pobiega
Pobiegaโ€ข2y ago
kinda
Angius
Angiusโ€ข2y ago
var secondChairFromTheLeft = new Chair(); Sure
Soinagie
SoinagieOPโ€ข2y ago
Yeah you just named it
Akseli
Akseliโ€ข2y ago
lets say you have a dog, called jerry. when you talk about jerry to someone, you say jerry (the name), you dont take the dog to your hands and shove it in their face, you just reference to the dog (object) with a name
Soinagie
SoinagieOPโ€ข2y ago
So I could use it now This specific object
Pobiega
Pobiegaโ€ข2y ago
you could use it before too
var list = new List<Car>
{
new Car("black"),
new Car("black"),
new Car("black"),
};

list[1].Color = "blue";
var list = new List<Car>
{
new Car("black"),
new Car("black"),
new Car("black"),
};

list[1].Color = "blue";
this is fine
Soinagie
SoinagieOPโ€ข2y ago
Before what?
Pobiega
Pobiegaโ€ข2y ago
before "giving it a name"
Soinagie
SoinagieOPโ€ข2y ago
Sorry I dont know anything about lists yet
Pobiega
Pobiegaโ€ข2y ago
Look you're probably overthinking this by a lot
Soinagie
SoinagieOPโ€ข2y ago
C# is object oriented language and I dont know what these objects are
Pobiega
Pobiegaโ€ข2y ago
you kinda do you understood just fine when I did the myCar = sameCar thing you understood that changing one changed the other, as they were the same object but when I made them different cars, you understood that modifying one doesnt modify the other
Akseli
Akseliโ€ข2y ago
hes trolling
Soinagie
SoinagieOPโ€ข2y ago
So for example car.(color) is an object? Or is it a type Or something else
Pobiega
Pobiegaโ€ข2y ago
int car.(color) is not valid code so I cant tell
Soinagie
SoinagieOPโ€ข2y ago
Oops Remove int
Pobiega
Pobiegaโ€ข2y ago
there is no syntax to "write an object" new T will create a new object of type T thats it thats the closest thing we get
Console.WriteLine(new Car().Color);
Console.WriteLine(new Car().Color);
this is valid code, for example but its kinda pointless, as you can't refer to the object any more and it will be cleaned up
Soinagie
SoinagieOPโ€ข2y ago
Why would I make new objects?
Pobiega
Pobiegaโ€ข2y ago
you almost always "capture" the object and store its reference in a variable, so you can do things with it because C# is object oriented
circles.png
circles.pngโ€ข2y ago
to structure data
Pobiega
Pobiegaโ€ข2y ago
its how we write code if your application is a car inventory program isnt it useful to keep track of cars?
Soinagie
SoinagieOPโ€ข2y ago
And I still dont know what that means
Servator
Servatorโ€ข2y ago
@Soinagie Almost everything is an object in OOP programming
Pobiega
Pobiegaโ€ข2y ago
you keep going around in circles
Servator
Servatorโ€ข2y ago
Do you know why literally everything has ".ToString()" method ?
Soinagie
SoinagieOPโ€ข2y ago
Wdym?
Akseli
Akseliโ€ข2y ago
hes literally trolling, if hes at this level of basic like literally grandpa level he shouldnt know about copy semantics but he did and thats how he exposed that hes trolling
Servator
Servatorโ€ข2y ago
Pobiega
Pobiegaโ€ข2y ago
I'm starting to agree with you
Servator
Servatorโ€ข2y ago
Soinagie
SoinagieOPโ€ข2y ago
If you're not willing to help you don't have to
circles.png
circles.pngโ€ข2y ago
but whatever im kinda bored
Servator
Servatorโ€ข2y ago
There is an "Object" class @Soinagie Every classes inherits that Object class
TheRanger
TheRangerโ€ข2y ago
Object-oriented programming
Object-oriented programming (OOP) is a programming paradigm based on the concept of "objects", which can contain data and code. The data is in the form of fields (often known as attributes or properties), and the code is in the form of procedures (often known as methods). A common feature of objects is that procedures (or methods) are attached ...
circles.png
circles.pngโ€ข2y ago
and the object class has a (virtual?) to string method
circles.png
circles.pngโ€ข2y ago
which means all objects will have it
Soinagie
SoinagieOPโ€ข2y ago
So all objects can be strings?
circles.png
circles.pngโ€ข2y ago
yes
Pobiega
Pobiegaโ€ข2y ago
no
circles.png
circles.pngโ€ข2y ago
mb then
Pobiega
Pobiegaโ€ข2y ago
all objects can be "turned into" strings
Servator
Servatorโ€ข2y ago
all objects are not strings but all strings are objects not the other way around
Soinagie
SoinagieOPโ€ข2y ago
I thought strings were a type
Pobiega
Pobiegaโ€ข2y ago
a type. string is a type.
Servator
Servatorโ€ข2y ago
classes are types there are primitive types and non-pritimitive types
Soinagie
SoinagieOPโ€ข2y ago
So color is a non-primitive type
Pobiega
Pobiegaโ€ข2y ago
string is a type, but an instance of a string is an object
Soinagie
SoinagieOPโ€ข2y ago
So "hello world" is an object?
Pobiega
Pobiegaโ€ข2y ago
yes
Servator
Servatorโ€ข2y ago
It's a string yes
Akseli
Akseliโ€ข2y ago
In the object-oriented programming paradigm, object can be a combination of variables, functions, and data structures; in particular in class-based variations of the paradigm it refers to a particular instance of a class. In a computer system, any time a new context is created based on some model, it is said that the model has been instantiated. In practice, this instance usually has a data structure in common with other instances, but the values stored in the instances are separate. Changing the values in one instance will then not interfere with the values of some other instance. In object-oriented programming, a class is an extensible program-code-template for creating objects, providing initial values for state (member variables) and implementations of behavior (member functions or methods)
circles.png
circles.pngโ€ข2y ago
system.drawing.color is (i think)
Servator
Servatorโ€ข2y ago
Usually you define an object with "new" keyword
MODiX
MODiXโ€ข2y ago
Pobiega#2671
REPL Result: Success
Console.WriteLine("hello world".GetType().FullName);
Console.WriteLine("hello world".GetType().FullName);
Console Output
System.String
System.String
Compile: 495.486ms | Execution: 64.641ms | React with โŒ to remove this embed.
Servator
Servatorโ€ข2y ago
But C# has a feature called implicit and explicit operator compiler uses that to create a string
Soinagie
SoinagieOPโ€ข2y ago
So if I do int x=100 then x is an object?
Akseli
Akseliโ€ข2y ago
stop introducing more and more unrelated things, the valid explanation for objects is here ^
Pobiega
Pobiegaโ€ข2y ago
as ive told you, there is no easy way to write a line of code and point to a thing in the code and say "see, here is the object" it doesnt exist in code, it exists at runtime, in the computers memory we use variables to REFER to objects but that doesnt mean the variable IS the object
Soinagie
SoinagieOPโ€ข2y ago
Simple question do I need to know what objects are?
circles.png
circles.pngโ€ข2y ago
yes definitely
Pobiega
Pobiegaโ€ข2y ago
not to the level of understanding you seem to seek
Soinagie
SoinagieOPโ€ข2y ago
Then if I cant use objects why do I need to know about them
Pobiega
Pobiegaโ€ข2y ago
who said you cant use them
Soinagie
SoinagieOPโ€ข2y ago
.
Pobiega
Pobiegaโ€ข2y ago
var x = new Car(); is using an object its just that x isnt the object its a variable pointing to the object
Soinagie
SoinagieOPโ€ข2y ago
But this object was never created
Servator
Servatorโ€ข2y ago
[declaretation] = [assignment] [type] [name] = [value]
Soinagie
SoinagieOPโ€ข2y ago
I cant refer to something that doesnt exist
Pobiega
Pobiegaโ€ข2y ago
new Car() creates it
Servator
Servatorโ€ข2y ago
It creates it ^^
Soinagie
SoinagieOPโ€ข2y ago
So now x is an instance of car?
Pobiega
Pobiegaโ€ข2y ago
no, its a variable pointing to an instance of Car
Servator
Servatorโ€ข2y ago
Servator
Servatorโ€ข2y ago
yes exactly
Pobiega
Pobiegaโ€ข2y ago
x is never anything but a variable
Soinagie
SoinagieOPโ€ข2y ago
And whats that instance? Of car
Pobiega
Pobiegaโ€ข2y ago
Ok you are trolling
circles.png
circles.pngโ€ข2y ago
a lot of ones and zeros
Pobiega
Pobiegaโ€ข2y ago
pick up two pens. they are two different instances of "Pen"
Soinagie
SoinagieOPโ€ข2y ago
Yes they are So theyre 2 objects
Pobiega
Pobiegaโ€ข2y ago
sure
Soinagie
SoinagieOPโ€ข2y ago
Then where did you use an object? If x isnt an object
Pobiega
Pobiegaโ€ข2y ago
creating it is using it
Soinagie
SoinagieOPโ€ข2y ago
And car is class
Pobiega
Pobiegaโ€ข2y ago
x.Color is using an object etc
circles.png
circles.pngโ€ข2y ago
class is the class in classify or classification
Pobiega
Pobiegaโ€ข2y ago
just because x itself isnt the object doesnt mean you cant interact with the object with the variable
Soinagie
SoinagieOPโ€ข2y ago
And car is this object? And its name is x?
Pobiega
Pobiegaโ€ข2y ago
go away troll
Soinagie
SoinagieOPโ€ข2y ago
Or is it its value Tbh I dont know the differnce
Servator
Servatorโ€ข2y ago
x just refers to an object real object is new Car()
Soinagie
SoinagieOPโ€ข2y ago
So its it name
Servator
Servatorโ€ข2y ago
[declaretation] = [assignment] [type] [name] = [value]
Soinagie
SoinagieOPโ€ข2y ago
And you can refer to that specific object
Servator
Servatorโ€ข2y ago
yes
Pobiega
Pobiegaโ€ข2y ago
(simplification)
Akseli
Akseliโ€ข2y ago
imagine doing this to an actual teacher in school holy shit i wish i back in primary school
Servator
Servatorโ€ข2y ago
I wish i was curious like him when i start coding
Soinagie
SoinagieOPโ€ข2y ago
Wdym by that?
Servator
Servatorโ€ข2y ago
except i was 10 but still value is right side of = declaration part is left side of = string text = "Hello" for example it doesn't need to be a class
Soinagie
SoinagieOPโ€ข2y ago
Both x=10 and 10=x mean the same
Servator
Servatorโ€ข2y ago
no = is used for assignment in programming languages (most of them) not for comparison
Soinagie
SoinagieOPโ€ข2y ago
Yeah I assign value 10 to x
Servator
Servatorโ€ข2y ago
= means literally get the value (right side of ๐Ÿ™‚ and put it in left side of =
MODiX
MODiXโ€ข2y ago
Samarichitane#3472
REPL Result: Success
int x = 1;

Console.WriteLine(x);

x = 5;

Console.WriteLine(x);
int x = 1;

Console.WriteLine(x);

x = 5;

Console.WriteLine(x);
Console Output
1
5
1
5
Compile: 522.035ms | Execution: 27.166ms | React with โŒ to remove this embed.
Soinagie
SoinagieOPโ€ข2y ago
So x isnt 10 but 10 is x?
Servator
Servatorโ€ข2y ago
what is 10 ?
Soinagie
SoinagieOPโ€ข2y ago
Int
Servator
Servatorโ€ข2y ago
Servator
Servatorโ€ข2y ago
but "10" doesn't refer to a variable
circles.png
circles.pngโ€ข2y ago
left side is always the target
Servator
Servatorโ€ข2y ago
Compiler doesn't know is it variable or not It's just an int like you said not reference or an object
TheRanger
TheRangerโ€ข2y ago
a human's name can be Soinagie, but a Soinagie's Name can't be a human
Soinagie
SoinagieOPโ€ข2y ago
So I assign value of right thing to the left thing
Servator
Servatorโ€ข2y ago
yes
Soinagie
SoinagieOPโ€ข2y ago
And then x is a object new Car
Servator
Servatorโ€ข2y ago
yes
Pobiega
Pobiegaโ€ข2y ago
(no) if x was the object, then how on earth would var y = x; be valid?
Soinagie
SoinagieOPโ€ข2y ago
And new always means I create an object
TheRanger
TheRangerโ€ข2y ago
var tails = new Fox();
var miles = tails;
var tails = new Fox();
var miles = tails;
Pobiega
Pobiegaโ€ข2y ago
there is still only 1 object
TheRanger
TheRangerโ€ข2y ago
miles and tails refer to the same fox
Soinagie
SoinagieOPโ€ข2y ago
Then whats the point of keyword "new"? Yeah and you can use both interchangibly
Pobiega
Pobiegaโ€ข2y ago
but they are not the object they are references to the same object they are not "the name of the object"
TheRanger
TheRangerโ€ข2y ago
in a sonic game, when you start a new level, they do new Sonic(); and stuff
Soinagie
SoinagieOPโ€ข2y ago
Reference is a name You refer to me by using my name
Pobiega
Pobiegaโ€ข2y ago
so say reference dont say name
Servator
Servatorโ€ข2y ago
We access references with name
TheRanger
TheRangerโ€ข2y ago
var soinagie = new Human();
soinagie.Jump();
var soinagie = new Human();
soinagie.Jump();
Soinagie
SoinagieOPโ€ข2y ago
Then this specific new human named soinagie jumps
TheRanger
TheRangerโ€ข2y ago
yes
Soinagie
SoinagieOPโ€ข2y ago
And soinagie is an instance of class human
TheRanger
TheRangerโ€ข2y ago
yes
Soinagie
SoinagieOPโ€ข2y ago
Or type Class or type?
TheRanger
TheRangerโ€ข2y ago
a class is a type
Soinagie
SoinagieOPโ€ข2y ago
They're the same or is it like square and rectangle?
Pobiega
Pobiegaโ€ข2y ago
all classes are types, not all types are classes
TheRanger
TheRangerโ€ข2y ago
yes, a class is one of the subcategories of a type
Soinagie
SoinagieOPโ€ข2y ago
So a type is a kind of value (like color) and class is a template for objects with the same type
TheRanger
TheRangerโ€ข2y ago
not sure what you mean a class is a reference type
Soinagie
SoinagieOPโ€ข2y ago
Reference to what?
TheRanger
TheRangerโ€ข2y ago
in here for example, when you call Jump on soinagie, it knows that its refering to the human you just created
var tails = new Fox();
var miles = tails;
tails.Jump();
miles.Jump();
var tails = new Fox();
var miles = tails;
tails.Jump();
miles.Jump();
both miles and tails refer to the same fox
Soinagie
SoinagieOPโ€ข2y ago
Yeah
TheRanger
TheRangerโ€ข2y ago
so the same fox will jump twice
Soinagie
SoinagieOPโ€ข2y ago
I get it But class is a reference to what
Pobiega
Pobiegaโ€ข2y ago
its not a reference, its a "reference type"
Soinagie
SoinagieOPโ€ข2y ago
So its a kind of specific type of value? Like color?
TheRanger
TheRangerโ€ข2y ago
its a type of reference type of value is something else
Soinagie
SoinagieOPโ€ข2y ago
Then is it reference type or type of refernce?
TheRanger
TheRangerโ€ข2y ago
thats the same thing
Soinagie
SoinagieOPโ€ข2y ago
And what is it? Its a template for creating objects
TheRanger
TheRangerโ€ข2y ago
yeah, u can have a single object, and multiple variables refer to the same object, like tails and fox value types cant
Soinagie
SoinagieOPโ€ข2y ago
Isnt refering and containg value essentialy the same? You use that value in both cases
TheRanger
TheRangerโ€ข2y ago
idk i dont really focus on these terms
Soinagie
SoinagieOPโ€ข2y ago
You just gave me a link to refernce types which separetes these two
TheRanger
TheRangerโ€ข2y ago
integer is a value type
Soinagie
SoinagieOPโ€ข2y ago
Tails is a refernce type then?
TheRanger
TheRangerโ€ข2y ago
Fox is
Soinagie
SoinagieOPโ€ข2y ago
And tails is...
TheRanger
TheRangerโ€ข2y ago
a variable
Soinagie
SoinagieOPโ€ข2y ago
What
TheRanger
TheRangerโ€ข2y ago
that refers to the object fox you just created
Soinagie
SoinagieOPโ€ข2y ago
I refers to fox Both refer to fox
Pobiega
Pobiegaโ€ข2y ago
they both refer to a fox, the same fox. they are not references to the class itself
Soinagie
SoinagieOPโ€ข2y ago
Then tails isnt a variable, its a reference
Akseli
Akseliโ€ข2y ago
this is still going? cmon guys
TheRanger
TheRangerโ€ข2y ago
tails IS a variable
Soinagie
SoinagieOPโ€ข2y ago
Why?
Akseli
Akseliโ€ข2y ago
tails is a reference
Soinagie
SoinagieOPโ€ข2y ago
. .
TheRanger
TheRangerโ€ข2y ago
or a reference variable, i guess u can call it that
Akseli
Akseliโ€ข2y ago
its both a variable and a reference reference type and a reference are 2 seperate things
Soinagie
SoinagieOPโ€ข2y ago
And same goes for miles
TheRanger
TheRangerโ€ข2y ago
yes, reference, and reference type are 2 different things
Soinagie
SoinagieOPโ€ข2y ago
What๐Ÿ˜ญ
streepje8
streepje8โ€ข2y ago
Type = A Car In General Object = A Specific Car Variable = That Car Over There
Soinagie
SoinagieOPโ€ข2y ago
Isnt that car over there also a specific car? I dont think so
streepje8
streepje8โ€ข2y ago
Its not about the car, its about the pointing to a car a variable is the thing that points to it
Soinagie
SoinagieOPโ€ข2y ago
Yeah you point to a specific car
Akseli
Akseliโ€ข2y ago
insanetrollface
TheRanger
TheRangerโ€ข2y ago
yes, think of life as a program, it created 100 million cars, and you have a car, you want to know which car to use
Soinagie
SoinagieOPโ€ข2y ago
In both cases
streepje8
streepje8โ€ข2y ago
Ok no the object is what you are pointing to and you are the variable you are not a car
Soinagie
SoinagieOPโ€ข2y ago
How am I relevant?
streepje8
streepje8โ€ข2y ago
If you are pointing to a car you are a sort of variable
Akseli
Akseliโ€ข2y ago
one person go at a time and try to explain it, so there wont be any conflicts introduced to his mind
streepje8
streepje8โ€ข2y ago
(its more complicated than that but this is the simple version) fair i feel like all of us mixing is making it more confusing haha
Pobiega
Pobiegaโ€ข2y ago
we've been trying to explain that for the last 2 hours
Dusty
Dustyโ€ข2y ago
and it's very entertaining (no offense with that, I like it that you guys try your best)
Akseli
Akseliโ€ข2y ago
he is trolling but i enjoy watching it
Soinagie
SoinagieOPโ€ข2y ago
They* And Im not I just want to understand that
streepje8
streepje8โ€ข2y ago
Im not sure but i dont want to be rude to them if im wrong
Dusty
Dustyโ€ข2y ago
Idk actually, I've seen other people that don't understand it for weeks until a bit of practical experience
streepje8
streepje8โ€ข2y ago
Ill just leave this convo and read back what came out of it haha
Akseli
Akseliโ€ข2y ago
scroll up and you will see
Soinagie
SoinagieOPโ€ข2y ago
Ok @implicit electron can you explain to me varaiables and objects then?
Dusty
Dustyโ€ข2y ago
If you wanna understand it go and write some programs, after a few days you'll get a better understanding ?
TheRanger
TheRangerโ€ข2y ago
ur an object of human, Soinagie is ur variable, when someone calls ur name, we know we are refering to you
Soinagie
SoinagieOPโ€ข2y ago
So variable is a specific object Or a reference to specific object So in case int x =10 x is both a variable and object
streepje8
streepje8โ€ข2y ago
I can't wait for the confusion when they figure out that an object's type is object
TheRanger
TheRangerโ€ข2y ago
careful, int isn't a reference type 10 isn't an object
Soinagie
SoinagieOPโ€ข2y ago
X is
Dusty
Dustyโ€ข2y ago
you need to explain the difference between reference and value types
Soinagie
SoinagieOPโ€ข2y ago
Ok @implicit electron only talk for now please
TheRanger
TheRangerโ€ข2y ago
no, x doesnt refer to 10, x itself is 10 when you talk about int, u are talking about a value type, not a reference type
Soinagie
SoinagieOPโ€ข2y ago
I dont know the difference
TheRanger
TheRangerโ€ข2y ago
take baby steps, fully understand one of them first
Soinagie
SoinagieOPโ€ข2y ago
I mean you can write 10 a bunch of times So they're new objects And they're all the same variable? Then which one Im supposed to learn first?
TheRanger
TheRangerโ€ข2y ago
well you have some idea about reference types right? might need to continue to finish learning that first
Soinagie
SoinagieOPโ€ข2y ago
I dont think I have
TheRanger
TheRangerโ€ข2y ago
i gave you an example of miles and tails, what did you not understand from that
Soinagie
SoinagieOPโ€ข2y ago
Then whats the difference between variable and refernce type?
TheRanger
TheRangerโ€ข2y ago
Human is a reference type
Soinagie
SoinagieOPโ€ข2y ago
I thought human was a class
TheRanger
TheRangerโ€ข2y ago
well, class is a reference type same meaning we did mention that above, i think
Soinagie
SoinagieOPโ€ข2y ago
And what specifically is a refence type?
TheRanger
TheRangerโ€ข2y ago
didnt we just explain that?
Soinagie
SoinagieOPโ€ข2y ago
.
TheRanger
TheRangerโ€ข2y ago
thats a different issue
Dusty
Dustyโ€ข2y ago
explaining that is way easier than the concept of reference types though
Soinagie
SoinagieOPโ€ข2y ago
Int is a type
Dusty
Dustyโ€ข2y ago
yes
TheRanger
TheRangerโ€ข2y ago
Int is a type, but not a reference type its a Value type
Soinagie
SoinagieOPโ€ข2y ago
And reference types are made up types Like color
Pobiega
Pobiegaโ€ข2y ago
No. Color could very well be either a value type or a reference type, we cant tell without being more specific about what color you mean
Soinagie
SoinagieOPโ€ข2y ago
Why is programming so hard to learn
TheRanger
TheRangerโ€ข2y ago
depends on the person
TotallyJustin
TotallyJustinโ€ข2y ago
Itโ€™s not
Dusty
Dustyโ€ข2y ago
It's all learning by doing imho
Soinagie
SoinagieOPโ€ข2y ago
I mean car(color)
Pobiega
Pobiegaโ€ข2y ago
I would highly recommend you get started programming, instead of wondering on the theoretical definition of every single term
Soinagie
SoinagieOPโ€ข2y ago
There is no default color type in C# You create it So its made up
Pobiega
Pobiegaโ€ข2y ago
but what if I "made" it like...
enum Color
{
Red,
Blue
}
enum Color
{
Red,
Blue
}
just because I made it doesnt mean its a reference type you can make value types too, if you want
Soinagie
SoinagieOPโ€ข2y ago
And its a variable or refernce type? The code you just made
Pobiega
Pobiegaโ€ข2y ago
thats an enum, its neither its a value type
Thinker
Thinkerโ€ข2y ago
@Akseli please don't assume people are trolling, it's just rude and disrespectful in the case that the person is genuinely sincere
Soinagie
SoinagieOPโ€ข2y ago
Then how is it relevant?
Akseli
Akseliโ€ข2y ago
its not an assumption
Pobiega
Pobiegaโ€ข2y ago
because you just claimed all "made up types" are reference types which they are not
Thinker
Thinkerโ€ข2y ago
yes it is, where did they state they are trolling
TotallyJustin
TotallyJustinโ€ข2y ago
Soinagie you wonโ€™t get anywhere if you get stuck trying to find the definition of every little thing, just find something simple to make, and start making it. Youโ€™ll learn what various terms mean as you go along and apply them to your own applications
MODiX
MODiXโ€ข2y ago
TheRanger#3357
REPL Result: Success
public struct Fox
{
public int Speed;

public Fox()
{
Speed = 0;
}
}

var tails = new Fox();
var miles = tails;
tails.Speed = 10;
Console.WriteLine(miles.Speed);
public struct Fox
{
public int Speed;

public Fox()
{
Speed = 0;
}
}

var tails = new Fox();
var miles = tails;
tails.Speed = 10;
Console.WriteLine(miles.Speed);
Console Output
0
0
Compile: 620.882ms | Execution: 33.214ms | React with โŒ to remove this embed.
Akseli
Akseliโ€ข2y ago
read the convo from start...
Thinker
Thinkerโ€ข2y ago
700 messages?
MODiX
MODiXโ€ข2y ago
TheRanger#3357
REPL Result: Success
public class Fox
{
public int Speed;

public Fox()
{
Speed = 0;
}
}

var tails = new Fox();
var miles = tails;
tails.Speed = 10;
Console.WriteLine(miles.Speed);
public class Fox
{
public int Speed;

public Fox()
{
Speed = 0;
}
}

var tails = new Fox();
var miles = tails;
tails.Speed = 10;
Console.WriteLine(miles.Speed);
Console Output
10
10
Compile: 569.295ms | Execution: 43.221ms | React with โŒ to remove this embed.
Akseli
Akseliโ€ข2y ago
you only need to read the first 100 to see it
TheRanger
TheRangerโ€ข2y ago
@Soinagie tell me the difference between the 2 codes i posted above
Thinker
Thinkerโ€ข2y ago
if you don't want to help then just... leave this thread
Soinagie
SoinagieOPโ€ข2y ago
Theres a class and struct But I dont know how they're different
TheRanger
TheRangerโ€ข2y ago
what about the Console output? why did one print 0 , and the other printed 10?
Soinagie
SoinagieOPโ€ข2y ago
Bc fox wasnt a class? In 1st one
TheRanger
TheRangerโ€ข2y ago
yeah, but why
Soinagie
SoinagieOPโ€ข2y ago
I dont know
TheRanger
TheRangerโ€ข2y ago
simple this
var miles = tails;
var miles = tails;
Thinker
Thinkerโ€ข2y ago
I personally can't find anything that suggests anything other than that this person is just trying to understand.
TheRanger
TheRangerโ€ข2y ago
cloned tails so now you have 2 foxes
Soinagie
SoinagieOPโ€ข2y ago
Cloned?
TheRanger
TheRangerโ€ข2y ago
like, copied
Soinagie
SoinagieOPโ€ข2y ago
Where
TheRanger
TheRangerโ€ข2y ago
here
Soinagie
SoinagieOPโ€ข2y ago
Miles and tails arent foxes
Akseli
Akseliโ€ข2y ago
just try to help him, im not bothered anymore
TheRanger
TheRangerโ€ข2y ago
they are
Soinagie
SoinagieOPโ€ข2y ago
They're a value for a fox Or a refernce Or something else I dont know
TheRanger
TheRangerโ€ข2y ago
since fox is a struct in the first code, the variable isnt a reference anymore
Soinagie
SoinagieOPโ€ข2y ago
I dont know what a struct is really
TheRanger
TheRangerโ€ข2y ago
its a value type, like Int Int is a struct when you do var miles = tails, it copies tails and assigns it to miles because Fox is a struct, not a class
Soinagie
SoinagieOPโ€ข2y ago
And why does it work with class fox? What does that class do?
TheRanger
TheRangerโ€ข2y ago
because class is a reference type, struct is a value type many variables can refer to the same object, struct cant
Soinagie
SoinagieOPโ€ข2y ago
Why does it matter if it was copied?
TheRanger
TheRangerโ€ข2y ago
depends on the programmer
Soinagie
SoinagieOPโ€ข2y ago
If it cant reference it Since its not a class
TheRanger
TheRangerโ€ข2y ago
do you want it to be copied or not
Soinagie
SoinagieOPโ€ข2y ago
No but it still doesmr matter It cant even get access to it
TheRanger
TheRangerโ€ข2y ago
if int is a class
Soinagie
SoinagieOPโ€ข2y ago
You just said that int isnt a class
TheRanger
TheRangerโ€ข2y ago
and you have many 1's in your program, what if you changed 1 to 2 all of the 1's in ur program will become 2 if
Soinagie
SoinagieOPโ€ข2y ago
If what?
TheRanger
TheRangerโ€ข2y ago
sounds like ur not good at english, no offense so i believe its hard to communicate with you
Soinagie
SoinagieOPโ€ข2y ago
Ok but what did you mean with that?
MODiX
MODiXโ€ข2y ago
TheRanger#3357
if int is a class
Quoted by
<@!105026391237480448> from #what's an object? (click here)
React with โŒ to remove this embed.
Pobiega
Pobiegaโ€ข2y ago
note how he said if
TheRanger
TheRangerโ€ข2y ago
i was saying what if int is a class say you have a company, with 20 employes that have 5000 salaries if you tried to change 5000 to 10000 all of the 20 employess will have 10000 salaries i hope my example isnt bad lol brb 5 minutes
Soinagie
SoinagieOPโ€ข2y ago
There are no refernces here
Pobiega
Pobiegaโ€ข2y ago
thats what the "if" was for if int was a reference type, it would be impractical
Soinagie
SoinagieOPโ€ข2y ago
Where is the "if" in this example? What even does "if" has to do with any of it?
Pobiega
Pobiegaโ€ข2y ago
if int was a reference type, changing 5000 in one place would change it in all the places
Soinagie
SoinagieOPโ€ข2y ago
Isnt it salary=5000
Pobiega
Pobiegaโ€ข2y ago
if as in the english word if, not the keyword.
Soinagie
SoinagieOPโ€ข2y ago
And you change it to salary =10000 Then is it keyword or english word?
TheRanger
TheRangerโ€ข2y ago
i was speaking about the contents of the number itself, not letting the variable point to another number
Soinagie
SoinagieOPโ€ข2y ago
Number is the content 10 is 10 Theres nothing more to it How does variable "point to"?
Pobiega
Pobiegaโ€ข2y ago
with value types, they dont with reference types, thats how programming with reference types work
TheRanger
TheRangerโ€ข2y ago
say for example you have defined a struct color
Soinagie
SoinagieOPโ€ข2y ago
So strings and classes are reference types, rest of them are value types?
MODiX
MODiXโ€ข2y ago
TheRanger#3357
REPL Result: Success
public struct Color
{
public int red;
public int green;
public int blue;
}


var color = new Color { red = 255 };
var anotherColor = color;
color.red = 0;
Console.WriteLine(anotherColor.red);
public struct Color
{
public int red;
public int green;
public int blue;
}


var color = new Color { red = 255 };
var anotherColor = color;
color.red = 0;
Console.WriteLine(anotherColor.red);
Console Output
255
255
Compile: 648.509ms | Execution: 37.902ms | React with โŒ to remove this embed.
TheRanger
TheRangerโ€ข2y ago
tell me why that printed 255
MODiX
MODiXโ€ข2y ago
TheRanger#3357
REPL Result: Success
public class Color
{
public int red;
public int green;
public int blue;
}


var color = new Color { red = 255 };
var anotherColor = color;
color.red = 64;
Console.WriteLine(anotherColor.red);
public class Color
{
public int red;
public int green;
public int blue;
}


var color = new Color { red = 255 };
var anotherColor = color;
color.red = 64;
Console.WriteLine(anotherColor.red);
Console Output
64
64
Compile: 590.516ms | Execution: 35.456ms | React with โŒ to remove this embed.
Soinagie
SoinagieOPโ€ข2y ago
You asked me similiar question while ago and I still don't know
TheRanger
TheRangerโ€ข2y ago
and why that printed 64 because one is struct(a value type) and other is class(a reference type)
Soinagie
SoinagieOPโ€ข2y ago
and I dont know the difference
Pobiega
Pobiegaโ€ข2y ago
that is the difference
TheRanger
TheRangerโ€ข2y ago
in the first one, color and another color's red is 255 in the 2nd one, color and another color points to a color that has 255 red
Soinagie
SoinagieOPโ€ข2y ago
but another color what defined as 255
TheRanger
TheRangerโ€ข2y ago
wdym
Soinagie
SoinagieOPโ€ข2y ago
anotherColor = color
TheRanger
TheRangerโ€ข2y ago
in which code?
Soinagie
SoinagieOPโ€ข2y ago
color.red= 0 in 1st
TheRanger
TheRangerโ€ข2y ago
whjat about it?
Soinagie
SoinagieOPโ€ข2y ago
so it should print 0
TheRanger
TheRangerโ€ข2y ago
why should it, i set color's red to be 0, not anotherColor's red
Soinagie
SoinagieOPโ€ข2y ago
yeah and anotherColor = color so they have the same value
TheRanger
TheRangerโ€ข2y ago
it got copied thats how value types work
Soinagie
SoinagieOPโ€ข2y ago
I still dont know what you mean by that
TheRanger
TheRangerโ€ข2y ago
when u do anotherColor = color its like u did anotherColor = new Color { red = 255 };
Soinagie
SoinagieOPโ€ข2y ago
yeah they both are 255
TheRanger
TheRangerโ€ข2y ago
yeah, however in the first one, i only changed color's red to be 0, anotherColor's red stayed the same
Soinagie
SoinagieOPโ€ข2y ago
but they're now the same thing now essentialy they have the same values
TheRanger
TheRangerโ€ข2y ago
at first yes, but changed one of their reds
Soinagie
SoinagieOPโ€ข2y ago
but you did the same with class color and it came out different it shouldn't have
TheRanger
TheRangerโ€ข2y ago
exactly why not?
Soinagie
SoinagieOPโ€ข2y ago
bc you set anotherColor as 255
TheRanger
TheRangerโ€ข2y ago
because they are the same object
Soinagie
SoinagieOPโ€ข2y ago
and in struct they're not?
TheRanger
TheRangerโ€ข2y ago
no it got copied like i said
Soinagie
SoinagieOPโ€ข2y ago
copying doesnt erase a value
TheRanger
TheRangerโ€ข2y ago
it didnt erase it where did it erase it?
Soinagie
SoinagieOPโ€ข2y ago
in color.red = 0 but it still printed 255
TheRanger
TheRangerโ€ข2y ago
i printed anotherColor's red not color's red
Soinagie
SoinagieOPโ€ข2y ago
and same goes for 2nd code you did the same thing
TheRanger
TheRangerโ€ข2y ago
yes, because anotherColor and color refer to the same object in the 2nd code
Soinagie
SoinagieOPโ€ข2y ago
then why use struct class?
TheRanger
TheRangerโ€ข2y ago
whats a struct class
Soinagie
SoinagieOPโ€ข2y ago
public struct Color
TheRanger
TheRangerโ€ข2y ago
to copy data without affecting the original like u see above
Soinagie
SoinagieOPโ€ข2y ago
I still don't understand this copying thing
TheRanger
TheRangerโ€ข2y ago
but now you see the difference, right? i really have to go, cya later well u can try messing around in ur visual studio with that code
Soinagie
SoinagieOPโ€ข2y ago
maybe, kinda?
TheRanger
TheRangerโ€ข2y ago
$refvsvalue
Soinagie
SoinagieOPโ€ข2y ago
but you defied anotherColor as color so it should be 0 even without it, There's nowhere stated that anotherColor=255 you did anotherColor= color in both but it only worked in 1 and it doesn't make any sense to me
TheRanger
TheRangerโ€ข2y ago
let me tell you how it actually works in the 2nd code new Color { red = 255 }; creates a value of that color and stores it somewhere in the memory and variable color refers to that value that is stored in the memory so when you do anotherColor = color now anotherColor points to the same value in the same memory location as color but in the first code var color = new Color { red = 255}; stores the value in variable color itself it is not stored somewhere else in the memory, it is stored in variable color itself so when you do anotherColor = color in the first code it copies the value that is stored in variable color, and takes it again for struct, var color = new Color { red = 255}; stores the value in variable color itself for class var color = new Color { red = 255}; stores the reference of the value for struct, var anotherColor = color copies the value that is stored in variable color itself for class, var anotherColor = color copies the reference that refers to the value that you initialized with new Color { red = 255};
Anton
Antonโ€ข2y ago
I think thinking of this in terms of memory can be easier to understand. A variable refers to a named slot in memory. You can make new named slots by declaring variables. You can load data into that named slot like this variableName = data. Variables have types, which define the size of the memory slot they identify and what data can go into that slot. Objects are just multiple named memory slots grouped together into a single one. The type of a memory slot can be a reference (pointer), which just means it has the address in memory of some other memory slot
Soinagie
SoinagieOPโ€ข2y ago
if it copies the value shouldn't it then be 255? for 1st one
TheRanger
TheRangerโ€ข2y ago
who should be 255?
Soinagie
SoinagieOPโ€ข2y ago
bc it copied the value like you said
TheRanger
TheRangerโ€ข2y ago
color or anotherColor?
Soinagie
SoinagieOPโ€ข2y ago
anotherColor got value from color which was 255
TheRanger
TheRangerโ€ข2y ago
yeah, it did
Soinagie
SoinagieOPโ€ข2y ago
then if its got that value it should print it
TheRanger
TheRangerโ€ข2y ago
it did
Soinagie
SoinagieOPโ€ข2y ago
crap I meant 0 Sorry You first set color to 255 but then change it to 0 its lower in the code so this one will be executed
TheRanger
TheRangerโ€ข2y ago
MODiX
MODiXโ€ข2y ago
TheRanger#3357
REPL Result: Success
public struct Color
{
public int red;
public int green;
public int blue;
}


var color = new Color { red = 255 };
var anotherColor = color;
color.red = 0;
Console.WriteLine(color.red);
Console.WriteLine(anotherColor.red);
public struct Color
{
public int red;
public int green;
public int blue;
}


var color = new Color { red = 255 };
var anotherColor = color;
color.red = 0;
Console.WriteLine(color.red);
Console.WriteLine(anotherColor.red);
Console Output
0
255
0
255
Compile: 682.319ms | Execution: 39.248ms | React with โŒ to remove this embed.
Soinagie
SoinagieOPโ€ข2y ago
but you set anotherColor = color so they're the same they have the same value
TheRanger
TheRangerโ€ข2y ago
nope, it got copied theyre not the same
Soinagie
SoinagieOPโ€ข2y ago
= means equals
TheRanger
TheRangerโ€ข2y ago
yeah ur point?
Soinagie
SoinagieOPโ€ข2y ago
that equals means these things are the same sorry if Im annoying you
TheRanger
TheRangerโ€ข2y ago
2 different objects that have the same red 255
Soinagie
SoinagieOPโ€ข2y ago
x = 5, that means x is equal 5 and nothing else
TheRanger
TheRangerโ€ข2y ago
ok in math u have x = 5 and y = x now y and x are 5 right?
Soinagie
SoinagieOPโ€ข2y ago
it cant equal x = 6 right
TheRanger
TheRangerโ€ข2y ago
what if lets say 5 = 20 is a thing
Soinagie
SoinagieOPโ€ข2y ago
it cant be how?
Servator
Servatorโ€ข2y ago
= for assignment == for comparison we talked about this :/
TheRanger
TheRangerโ€ข2y ago
they arent asking for comparison atm
Soinagie
SoinagieOPโ€ข2y ago
you cant assign a number other number
TheRanger
TheRangerโ€ข2y ago
mathematically u cant yeah i was giving an example ok so do u know pie 3.14?
Soinagie
SoinagieOPโ€ข2y ago
yeah
TheRanger
TheRangerโ€ข2y ago
x = pie and y = pie correct?
Soinagie
SoinagieOPโ€ข2y ago
yes
TheRanger
TheRangerโ€ข2y ago
what if i changed pie to 9 instead of 3.14
Soinagie
SoinagieOPโ€ข2y ago
its a constant
TheRanger
TheRangerโ€ข2y ago
i know but lets say we can change it
Soinagie
SoinagieOPโ€ข2y ago
ok?
TheRanger
TheRangerโ€ข2y ago
programatically what would the value of x and y be?
Soinagie
SoinagieOPโ€ข2y ago
9
TheRanger
TheRangerโ€ข2y ago
if pie is a class then yes, if its a struct, then no here is a better example
Soinagie
SoinagieOPโ€ข2y ago
is it all in a value or reference? or outside? like you do pie=3.14 then struct pie=x or all inside struct?
MODiX
MODiXโ€ข2y ago
TheRanger#3357
REPL Result: Success
public struct Pie
{
public float Value;

public Pie()
{
Value = 3.14f;
}
}


var x = new Pie();
var y = x;
x.Value = 9f;
Console.WriteLine(x.Value);
Console.WriteLine(y.Value);
public struct Pie
{
public float Value;

public Pie()
{
Value = 3.14f;
}
}


var x = new Pie();
var y = x;
x.Value = 9f;
Console.WriteLine(x.Value);
Console.WriteLine(y.Value);
Console Output
9
3.14
9
3.14
Compile: 590.352ms | Execution: 33.431ms | React with โŒ to remove this embed.
MODiX
MODiXโ€ข2y ago
TheRanger#3357
REPL Result: Success
public class Pie
{
public float Value;

public Pie()
{
Value = 3.14f;
}
}


var x = new Pie();
var y = x;
x.Value = 9f;
Console.WriteLine(x.Value);
Console.WriteLine(y.Value);
public class Pie
{
public float Value;

public Pie()
{
Value = 3.14f;
}
}


var x = new Pie();
var y = x;
x.Value = 9f;
Console.WriteLine(x.Value);
Console.WriteLine(y.Value);
Console Output
9
9
9
9
Compile: 651.824ms | Execution: 34.013ms | React with โŒ to remove this embed.
Soinagie
SoinagieOPโ€ข2y ago
why did you do new Pie()?
TheRanger
TheRangerโ€ข2y ago
to initialize it
Soinagie
SoinagieOPโ€ข2y ago
cant you do just Pie?
TheRanger
TheRangerโ€ข2y ago
no
Soinagie
SoinagieOPโ€ข2y ago
so I call all my methods with new?
TheRanger
TheRangerโ€ข2y ago
?
Soinagie
SoinagieOPโ€ข2y ago
Pie is a method right?
Anton
Antonโ€ข2y ago
pie is not a method
Servator
Servatorโ€ข2y ago
Your are missing the main point @Soinagie
TheRanger
TheRangerโ€ข2y ago
which Pie, the one next to new or next to class/struct?
Servator
Servatorโ€ข2y ago
He changed x's Value
Anton
Antonโ€ข2y ago
you're referring to the constructor probably
Servator
Servatorโ€ข2y ago
but Y's value is changed too Why ? Focus here
Servator
Servatorโ€ข2y ago
Soinagie
SoinagieOPโ€ข2y ago
bc x and y in reference type are treated as the same things?
TheRanger
TheRangerโ€ข2y ago
yes
Soinagie
SoinagieOPโ€ข2y ago
well thats I understand but it shouldn't apply a completly different logic to a different type
TheRanger
TheRangerโ€ข2y ago
what?
Soinagie
SoinagieOPโ€ข2y ago
I mean value type I dont understand value type
TheRanger
TheRangerโ€ข2y ago
not sure what u mean
Servator
Servatorโ€ข2y ago
It gets the all properties yet values are different values not bound to anything
Soinagie
SoinagieOPโ€ข2y ago
but theres "=" can we do another mathematical allegory? for value type?
TheRanger
TheRangerโ€ข2y ago
not sure what that means
Soinagie
SoinagieOPโ€ข2y ago
we did pie for refernce type
TheRanger
TheRangerโ€ข2y ago
yes
Soinagie
SoinagieOPโ€ข2y ago
what I mean is could you elaborate why "no"?
TheRanger
TheRangerโ€ข2y ago
that was an answer to ur question
Soinagie
SoinagieOPโ€ข2y ago
if pie is 9 and pie=x=y then both are 9s
TheRanger
TheRangerโ€ข2y ago
pie=x=y ? what?
Soinagie
SoinagieOPโ€ข2y ago
.
TheRanger
TheRangerโ€ข2y ago
if its a class or a struct?
Soinagie
SoinagieOPโ€ข2y ago
we did reference
TheRanger
TheRangerโ€ข2y ago
yeah
Soinagie
SoinagieOPโ€ข2y ago
class and I would pls like to do struct
TheRanger
TheRangerโ€ข2y ago
what about x = pie ?
Soinagie
SoinagieOPโ€ข2y ago
what about it?
TheRanger
TheRangerโ€ข2y ago
u pinged me for this
Soinagie
SoinagieOPโ€ข2y ago
yeah you explained reference type right?
TheRanger
TheRangerโ€ข2y ago
yes
Soinagie
SoinagieOPโ€ข2y ago
but for value type you just said "it doesnt happen"
TheRanger
TheRangerโ€ข2y ago
where did i say that what exactly doesn't happen ?
Soinagie
SoinagieOPโ€ข2y ago
. its not a 9 if its a struc
TheRanger
TheRangerโ€ข2y ago
heres a better example
MODiX
MODiXโ€ข2y ago
TheRanger#3357
REPL Result: Success
var pie = new Pie();
public struct Pie
{
public float Value;

public Pie()
{
Value = 3.14f;
}
}


var x = pie;
var y = x;
x.Value = 9f;
Console.WriteLine(x.Value);
Console.WriteLine(y.Value);
Console.WriteLine(pie.Value);
var pie = new Pie();
public struct Pie
{
public float Value;

public Pie()
{
Value = 3.14f;
}
}


var x = pie;
var y = x;
x.Value = 9f;
Console.WriteLine(x.Value);
Console.WriteLine(y.Value);
Console.WriteLine(pie.Value);
Console Output
9
3.14
3.14
9
3.14
3.14
Compile: 620.839ms | Execution: 32.997ms | React with โŒ to remove this embed.
TheRanger
TheRangerโ€ข2y ago
what did u notice in this?
Soinagie
SoinagieOPโ€ข2y ago
that y = x but they both show different values
TheRanger
TheRangerโ€ข2y ago
yeah
Soinagie
SoinagieOPโ€ข2y ago
and thats my problem
TheRanger
TheRangerโ€ข2y ago
it copied it
Soinagie
SoinagieOPโ€ข2y ago
if it copied it then shouldn't it be the same?
TheRanger
TheRangerโ€ข2y ago
no, a copy is a copy like u copy a file
Soinagie
SoinagieOPโ€ข2y ago
yeah its the same file with same value
TheRanger
TheRangerโ€ข2y ago
no, 2 different files, have equal data
Soinagie
SoinagieOPโ€ข2y ago
I means their contents are the same
TheRanger
TheRangerโ€ข2y ago
yes if you modified one of the contents of the first file would it also get modified in the 2nd file?
Soinagie
SoinagieOPโ€ข2y ago
no
TheRanger
TheRangerโ€ข2y ago
exactly thats how struct works
Soinagie
SoinagieOPโ€ข2y ago
wait so it creates a copy and then modifies it?
TheRanger
TheRangerโ€ข2y ago
yes
Soinagie
SoinagieOPโ€ข2y ago
and original value of 3.14 is never changed
TheRanger
TheRangerโ€ข2y ago
the one that is stored in y yes
Soinagie
SoinagieOPโ€ข2y ago
then what does var y = x do?
TheRanger
TheRangerโ€ข2y ago
i told u, it copies it u have a file called x with contents inside u copy pasted the file, and named it y
Soinagie
SoinagieOPโ€ข2y ago
y is the original and x is the copy of it
TheRanger
TheRangerโ€ข2y ago
other way x is the original, y is the copy be advised
Soinagie
SoinagieOPโ€ข2y ago
but you assigned 9 to x
TheRanger
TheRangerโ€ข2y ago
var y = x copies it if its a struct
Soinagie
SoinagieOPโ€ข2y ago
shouldn't then pie also be 9? if its an original
TheRanger
TheRangerโ€ข2y ago
ive never changed the value of pie
Soinagie
SoinagieOPโ€ข2y ago
so you created pie assigned it 3.14 created x assigned it 9 thats a version of pie
TheRanger
TheRangerโ€ข2y ago
yes
Soinagie
SoinagieOPโ€ข2y ago
and made y thats a copy of x
TheRanger
TheRangerโ€ข2y ago
i made y thats a copy of x before i changed x's value
Soinagie
SoinagieOPโ€ข2y ago
oohh right so if it'd be lower both'd be 9 right?
MODiX
MODiXโ€ข2y ago
TheRanger#3357
REPL Result: Success
var pie = new Pie();
public struct Pie
{
public float Value;

public Pie()
{
Value = 3.14f;
}
}


var x = pie;
x.Value = 9f;
var y = x;
Console.WriteLine(x.Value);
Console.WriteLine(y.Value);
Console.WriteLine(pie.Value);
var pie = new Pie();
public struct Pie
{
public float Value;

public Pie()
{
Value = 3.14f;
}
}


var x = pie;
x.Value = 9f;
var y = x;
Console.WriteLine(x.Value);
Console.WriteLine(y.Value);
Console.WriteLine(pie.Value);
Console Output
9
9
3.14
9
9
3.14
Compile: 652.569ms | Execution: 33.387ms | React with โŒ to remove this embed.
TheRanger
TheRangerโ€ข2y ago
yes
Soinagie
SoinagieOPโ€ข2y ago
ok Im kinda getting it so "=" in value types copies variables
TheRanger
TheRangerโ€ข2y ago
pretty much
Soinagie
SoinagieOPโ€ข2y ago
and my default thinking of "=" comes from refernce type
TheRanger
TheRangerโ€ข2y ago
might be more clearer in c/C++ everything is a value type there, it becomes a reference type if you put a * next to a variable
Soinagie
SoinagieOPโ€ข2y ago
ok anyway thank you very much for your time and for reference I genuinely wasn't trolling with that so you either do class or put * before a variable?
TheRanger
TheRangerโ€ข2y ago
i never said ur trolling class in C++ isnt a reference type
Soinagie
SoinagieOPโ€ข2y ago
sorry Im not planning on C++
TheRanger
TheRangerโ€ข2y ago
its just struct with public and private access modifiers
Soinagie
SoinagieOPโ€ข2y ago
ok so for c# this * doesnt't apply?
TheRanger
TheRangerโ€ข2y ago
only in unsafe context which is very dangerous, can freeze ur pc if you used it wrong
Soinagie
SoinagieOPโ€ข2y ago
ok I just won't use * then
TheRanger
TheRangerโ€ข2y ago
ull probably need it sometime in the future
Soinagie
SoinagieOPโ€ข2y ago
I dont want my pc frozen
TheRanger
TheRangerโ€ข2y ago
well if u used it right it wont freeze usually only useful if you want ur program to run faster/ or trying to execute some c++ code from a c++ dll
Soinagie
SoinagieOPโ€ข2y ago
Anyhow I need some time to process and revise all this information but I appreciate your help very very much and thank SylvDance
TheRanger
TheRangerโ€ข2y ago
np
Monsieur Wholesome
Monsieur Wholesomeโ€ข2y ago
what the
Monsieur Wholesome
Monsieur Wholesomeโ€ข2y ago
lordnaseMonkas
TheRanger
TheRangerโ€ข2y ago
well its now 1087 trollface
Monsieur Wholesome
Monsieur Wholesomeโ€ข2y ago
will we hit 1k?
TheRanger
TheRangerโ€ข2y ago
we already did
Angius
Angiusโ€ข2y ago
๐ŸŽ‰ Here's to another 1000!
arion
arionโ€ข2y ago
Ok can at least say its thorough
mtreit
mtreitโ€ข2y ago
PauseChamp we conclude what an object is?
TheRanger
TheRangerโ€ข2y ago
i think so
Pobiega
Pobiegaโ€ข2y ago
it got very sidetracked, many many times "What is an object?" "an object is an instance of a reference type" "and what is a reference type?" "well its a type that you get a reference too" "what is a reference?" etc and varying levels of abstraction back and forth
Monsieur Wholesome
Monsieur Wholesomeโ€ข2y ago
just a little bit
Servator
Servatorโ€ข2y ago
He try to learn fast (which is bad)
Soinagie
SoinagieOPโ€ข2y ago
Im not trying to learn fast, I just want to understand bare basics
Thinker
Thinkerโ€ข2y ago
Just gonna say, the bare basics does not mean having to understand everything that's going on. Knowing what a reference is is good for more advanced usage, but for the basics it's practically only necessary to know the surface level of it. Getting bogged down with all the tiny little details is just counter-productive.
Soinagie
SoinagieOPโ€ข2y ago
Sorry
Servator
Servatorโ€ข2y ago
You are not trying to learn fast yet like Thinker said you are trying to understand everything at once Don't rush into things yet
Accord
Accordโ€ข2y ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server