C
C#โ€ข17mo 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โ€ข17mo 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
Soinagieโ€ข17mo ago
So it's just a variable?
Angius
Angiusโ€ข17mo ago
No
Soinagie
Soinagieโ€ข17mo ago
Like x=10?
Angius
Angiusโ€ข17mo ago
A variable is the object's address, you could say
Soinagie
Soinagieโ€ข17mo ago
What address
Angius
Angiusโ€ข17mo ago
How you refer to that specific object Like, you have a Car. But which car do you mean?
Soinagie
Soinagieโ€ข17mo ago
I still don't know what objects are
Angius
Angiusโ€ข17mo ago
var myCar = new Car();
var yourCar = new Car();
var myCar = new Car();
var yourCar = new Car();
Soinagie
Soinagieโ€ข17mo ago
So Im not sure I understand
Angius
Angiusโ€ข17mo ago
Two different objects, two different cars So each has a different name There's my car, and there's your car
Soinagie
Soinagieโ€ข17mo ago
And they're both new cars?
Angius
Angiusโ€ข17mo ago
They're both cars
Soinagie
Soinagieโ€ข17mo ago
New cars
Angius
Angiusโ€ข17mo ago
new is how you instantiate an object in C#
Soinagie
Soinagieโ€ข17mo ago
What
Angius
Angiusโ€ข17mo ago
How you create a new instance of a car A new instance of an object
Soinagie
Soinagieโ€ข17mo ago
Idk even know what instantiate means๐Ÿ˜ญ
Angius
Angiusโ€ข17mo 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
Soinagieโ€ข17mo ago
Why make new instance of a car?
Angius
Angiusโ€ข17mo ago
A specific, existing, physical object Because you want an actual car Not just an idea of a car
Soinagie
Soinagieโ€ข17mo ago
You already have it just copy it
Angius
Angiusโ€ข17mo ago
What if both have different colors?
Soinagie
Soinagieโ€ข17mo ago
But you didn't write that anywhere
Angius
Angiusโ€ข17mo 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
Soinagieโ€ข17mo ago
Im confused
Angius
Angiusโ€ข17mo 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
Soinagieโ€ข17mo ago
What idea?
Pobiega
Pobiegaโ€ข17mo ago
Are two black fords the same car? no, they are two different instances of a black ford
Angius
Angiusโ€ข17mo ago
The idea of a thing, the concept of it, not the specific given thing
Soinagie
Soinagieโ€ข17mo ago
What?
Angius
Angiusโ€ข17mo 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
Soinagieโ€ข17mo ago
But only if you put that color in parentheses
Angius
Angiusโ€ข17mo ago
That's a constructor You can just... not have a constructor, and it can still work
Soinagie
Soinagieโ€ข17mo ago
Sorry I have no idea about the wording and in general Im just lost
Angius
Angiusโ€ข17mo 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
Soinagieโ€ข17mo ago
You just called myCar a variable Then isnt it a variable?
Angius
Angiusโ€ข17mo ago
The variable gives that object a name
Soinagie
Soinagieโ€ข17mo ago
So objects are variables
Angius
Angiusโ€ข17mo 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
Soinagieโ€ข17mo ago
What pobiega?
Angius
Angiusโ€ข17mo ago
@Pobiega Another user
Pobiega
Pobiegaโ€ข17mo ago
๐Ÿ‘‹
Soinagie
Soinagieโ€ข17mo ago
I dont understand
Angius
Angiusโ€ข17mo 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
Soinagieโ€ข17mo ago
But what about my name?
Pobiega
Pobiegaโ€ข17mo ago
What about it?
Angius
Angiusโ€ข17mo ago
It's how others can tell you apart from other people? It's how others can refer to you?
Soinagie
Soinagieโ€ข17mo ago
So its indetificator for an object?
Angius
Angiusโ€ข17mo ago
Yep
Pobiega
Pobiegaโ€ข17mo ago
in programming we say that "a variable points to an object"
Soinagie
Soinagieโ€ข17mo ago
And its a variable
Pobiega
Pobiegaโ€ข17mo ago
no its two different things. One points to the other
Soinagie
Soinagieโ€ข17mo ago
They just used var
Pobiega
Pobiegaโ€ข17mo ago
a name points to a person var variableName = new Person(); var variableName is indeed a variable but new Person() is not
Soinagie
Soinagieโ€ข17mo ago
Yeah so my identuficator is a variable
Pobiega
Pobiegaโ€ข17mo ago
yes
Soinagie
Soinagieโ€ข17mo ago
So my name is var
Pobiega
Pobiegaโ€ข17mo ago
no, var is a keyword variableName is the name
Soinagie
Soinagieโ€ข17mo ago
I meant short for a varaible
Pobiega
Pobiegaโ€ข17mo ago
okay, then yes
Soinagie
Soinagieโ€ข17mo ago
My name is a variable string Or something like that
Pobiega
Pobiegaโ€ข17mo ago
Soinagie is a "variable" that points to an object discord user
Soinagie
Soinagieโ€ข17mo 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โ€ข17mo 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
Soinagieโ€ข17mo ago
Type of what?
Pobiega
Pobiegaโ€ข17mo ago
a type. string is a type for example
Monsieur Wholesome
Monsieur Wholesomeโ€ข17mo 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โ€ข17mo ago
int, ยดCar` etc
Soinagie
Soinagieโ€ข17mo ago
Its a variable
Pobiega
Pobiegaโ€ข17mo ago
what is? a type? no
Soinagie
Soinagieโ€ข17mo ago
String
Pobiega
Pobiegaโ€ข17mo ago
no, thats type
Soinagie
Soinagieโ€ข17mo ago
And objects are types of what then?
Pobiega
Pobiegaโ€ข17mo ago
string myString;
string myString;
thats a variable called "myString" and the type is string objects are instances of types
Soinagie
Soinagieโ€ข17mo ago
What does that mean?
Pobiega
Pobiegaโ€ข17mo ago
thats what we just discussed with the cars and chairs
circles.png
circles.pngโ€ข17mo ago
objects are not types
Soinagie
Soinagieโ€ข17mo ago
.
Pobiega
Pobiegaโ€ข17mo 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
Soinagieโ€ข17mo ago
I very much appriciate your help but I doubt I'll understand any of this
circles.png
circles.pngโ€ข17mo ago
objects are instances of types
Soinagie
Soinagieโ€ข17mo ago
Why is thirdCar treated like an object?
Pobiega
Pobiegaโ€ข17mo ago
what do you mean by that its not?
Soinagie
Soinagieโ€ข17mo ago
Its just a copy of myCar
Pobiega
Pobiegaโ€ข17mo ago
no, its not a copy
circles.png
circles.pngโ€ข17mo ago
it is not a copy
Soinagie
Soinagieโ€ข17mo ago
Its the same
Pobiega
Pobiegaโ€ข17mo ago
its a new variable, pointing to the same car
circles.png
circles.pngโ€ข17mo ago
pointing = meaning third car is another name for my car
Soinagie
Soinagieโ€ข17mo ago
There is only newCar and all of these variables refer to it
Angius
Angiusโ€ข17mo 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
Soinagieโ€ข17mo ago
What does pointing= meaning mean?
circles.png
circles.pngโ€ข17mo ago
new <space> Car creates a new car
Pobiega
Pobiegaโ€ข17mo 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โ€ข17mo ago
both variables mean the same thing
Pobiega
Pobiegaโ€ข17mo ago
what do you think this snippet of code will print?
Soinagie
Soinagieโ€ข17mo ago
There are no "meaning" and "pointing" variables It'll print same car blue?
Pobiega
Pobiegaโ€ข17mo ago
Look at the last line of code Console.WriteLine(myCar.Color);
Soinagie
Soinagieโ€ข17mo ago
Yeah myCar = sameCar So it'll print sameCar With color blue
Pobiega
Pobiegaโ€ข17mo 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โ€ข17mo 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
Soinagieโ€ข17mo ago
Why did you put black there? If it isnt used
Pobiega
Pobiegaโ€ข17mo ago
to have an initial value
Soinagie
Soinagieโ€ข17mo ago
Why
Pobiega
Pobiegaโ€ข17mo ago
I wanted to demonstrate that they are the same object
Soinagie
Soinagieโ€ข17mo ago
You give it a value before you print it
Pobiega
Pobiegaโ€ข17mo ago
yes
Soinagie
Soinagieโ€ข17mo ago
And Car and myCar are different things?
Pobiega
Pobiegaโ€ข17mo 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
Soinagieโ€ข17mo ago
I thought Car was an object
Pobiega
Pobiegaโ€ข17mo ago
no, Car is a type.
Soinagie
Soinagieโ€ข17mo ago
I wanted to know about objects
Pobiega
Pobiegaโ€ข17mo ago
objects are instances of types you create an instance by using the new keyword
Soinagie
Soinagieโ€ข17mo ago
And I still don't know what that means
Pobiega
Pobiegaโ€ข17mo ago
so new Car() creates an object
Akseli
Akseliโ€ข17mo ago
object is an instance of a class
Soinagie
Soinagieโ€ข17mo ago
But newCar is a variable
Pobiega
Pobiegaโ€ข17mo ago
yes
Akseli
Akseliโ€ข17mo ago
class is a specific blueprint for the objects layout
Soinagie
Soinagieโ€ข17mo ago
So it isnt an object
Pobiega
Pobiegaโ€ข17mo 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
Soinagieโ€ข17mo ago
It'll print black I guess
Pobiega
Pobiegaโ€ข17mo ago
correct.
Soinagie
Soinagieโ€ข17mo ago
Could you please not use newCar as there already is word "new" being used and it just confuses me
Pobiega
Pobiegaโ€ข17mo ago
you're the one who used it I didn't. ^ you created it, I just went with it ๐Ÿ™‚
Soinagie
Soinagieโ€ข17mo ago
Bc I thought newCar and new Car are thevsame thing
Pobiega
Pobiegaโ€ข17mo ago
no ofc not especially not since new Car isnt valid new Car() is the parenthesis is not optional
Soinagie
Soinagieโ€ข17mo ago
Ok can we take it really slow please?
Pobiega
Pobiegaโ€ข17mo ago
sure
Soinagie
Soinagieโ€ข17mo ago
What is a type?
Pobiega
Pobiegaโ€ข17mo ago
You know how computers only actually work with 1s and 0s?
Soinagie
Soinagieโ€ข17mo ago
Yeah
Pobiega
Pobiegaโ€ข17mo 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
Soinagieโ€ข17mo ago
What object?
Pobiega
Pobiegaโ€ข17mo ago
an object no actual object yet, a theoretical one
Soinagie
Soinagieโ€ข17mo ago
And what is it?
Akseli
Akseliโ€ข17mo ago
are you guys trolling
Soinagie
Soinagieโ€ข17mo ago
Who?
Akseli
Akseliโ€ข17mo ago
an object is an instance of a class
Soinagie
Soinagieโ€ข17mo ago
And I dont know what instance of a class is
Angius
Angiusโ€ข17mo 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โ€ข17mo 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
Soinagieโ€ข17mo ago
Car isnt the same as string and int
Pobiega
Pobiegaโ€ข17mo 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
Soinagieโ€ข17mo ago
Sorry idk what get set are
Pobiega
Pobiegaโ€ข17mo ago
ignore it
Soinagie
Soinagieโ€ข17mo ago
I just wanted to learn from the top so I thought I should know what objects are first
Pobiega
Pobiegaโ€ข17mo 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
Soinagieโ€ข17mo ago
So methods have types?
Pobiega
Pobiegaโ€ข17mo ago
sure public string GetName() { ... } for example thats a method that returns a string
Soinagie
Soinagieโ€ข17mo ago
Wait a sec Before we speed off
Akseli
Akseliโ€ข17mo ago
no, types have methods but methods can have return types
Soinagie
Soinagieโ€ข17mo ago
Is getName a method?
Pobiega
Pobiegaโ€ข17mo ago
Akseli, you're really not helping at this point So if anyone is trolling, its you.
circles.png
circles.pngโ€ข17mo ago
yes
Soinagie
Soinagieโ€ข17mo ago
Ok so we made a string method
Pobiega
Pobiegaโ€ข17mo ago
a method that returns a string, yep
Soinagie
Soinagieโ€ข17mo ago
Wait
Pobiega
Pobiegaโ€ข17mo 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
Soinagieโ€ข17mo ago
It doesnt say anywhere that it returns
Pobiega
Pobiegaโ€ข17mo ago
sure it does. it MUST
Soinagie
Soinagieโ€ข17mo ago
Or is it implied
Akseli
Akseliโ€ข17mo ago
im just making sure no misinformation is fed
Soinagie
Soinagieโ€ข17mo ago
Since its not a void
Pobiega
Pobiegaโ€ข17mo ago
it won't compile if it doesnt return a string
circles.png
circles.pngโ€ข17mo ago
the word string, in that position, is the return type
Pobiega
Pobiegaโ€ข17mo ago
because we set its return type to string
Soinagie
Soinagieโ€ข17mo ago
I thought that you had to use "return" keyword For every non-void
Pobiega
Pobiegaโ€ข17mo ago
you do
Soinagie
Soinagieโ€ข17mo ago
And you didn't
Pobiega
Pobiegaโ€ข17mo ago
you see how I left out the body of the method with ... as the placeholder?
circles.png
circles.pngโ€ข17mo ago
thats in the implementation (code block which is hidden)
Soinagie
Soinagieโ€ข17mo ago
Im not sure if hiding things for begginers is a good solution but sure
circles.png
circles.pngโ€ข17mo ago
for brevity
Pobiega
Pobiegaโ€ข17mo ago
well I wanted you to focus on the important part the type in the method signature
Soinagie
Soinagieโ€ข17mo ago
What signature?
Pobiega
Pobiegaโ€ข17mo ago
public string GetName() thats a "method signature"
Soinagie
Soinagieโ€ข17mo ago
Its a method
Pobiega
Pobiegaโ€ข17mo 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
Soinagieโ€ข17mo ago
Ok so its creation of a method
Pobiega
Pobiegaโ€ข17mo ago
yeah
Soinagie
Soinagieโ€ข17mo ago
and its type is a creation of a method type?
Pobiega
Pobiegaโ€ข17mo ago
?
Soinagie
Soinagieโ€ข17mo ago
Or do you mean string
Pobiega
Pobiegaโ€ข17mo ago
its return type is string
Soinagie
Soinagieโ€ข17mo ago
So this block is creation of a method that'll return a string
Pobiega
Pobiegaโ€ข17mo 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
Soinagieโ€ข17mo ago
And thats important because?
Pobiega
Pobiegaโ€ข17mo 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
Soinagieโ€ข17mo ago
I mean you can assign numbers to cars
Pobiega
Pobiegaโ€ข17mo 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
Soinagieโ€ข17mo ago
But Im getting off track
arion
arionโ€ข17mo 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โ€ข17mo 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
Soinagieโ€ข17mo ago
Ok and why did you talk about Car and int not being compatible?
Pobiega
Pobiegaโ€ข17mo ago
because you asked why its important that methods have return types
Soinagie
Soinagieโ€ข17mo ago
I thought that they have to have them
Pobiega
Pobiegaโ€ข17mo ago
they do
Soinagie
Soinagieโ€ข17mo ago
Ok so objects are made up types
Pobiega
Pobiegaโ€ข17mo 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
Soinagieโ€ข17mo ago
But there is no myInt or yourint
Pobiega
Pobiegaโ€ข17mo ago
sure there is
MODiX
MODiXโ€ข17mo 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โ€ข17mo ago
I just made one
Soinagie
Soinagieโ€ข17mo ago
And its an object?
Pobiega
Pobiegaโ€ข17mo ago
myInt is a variable myChair was also a variable, technically.
Soinagie
Soinagieโ€ข17mo ago
It looks like a variable
Pobiega
Pobiegaโ€ข17mo ago
a variable POINTING TO AN OBJECT
Soinagie
Soinagieโ€ข17mo ago
And object being... Where does it point?
Pobiega
Pobiegaโ€ข17mo ago
to somewhere in memory
Soinagie
Soinagieโ€ข17mo ago
What does even that mean?
Pobiega
Pobiegaโ€ข17mo ago
new Car() returns a pointer to memory. you store that in a variable and use it
Soinagie
Soinagieโ€ข17mo ago
So objects are just things you can point towards?
circles.png
circles.pngโ€ข17mo 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โ€ข17mo ago
reading through this thread here it sounds like trolling but way to dedicated
Soinagie
Soinagieโ€ข17mo ago
Wow thanks So motivating
Akseli
Akseliโ€ข17mo 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
Soinagieโ€ข17mo ago
Isnt myCar now the same as new Car?
Akseli
Akseliโ€ข17mo ago
no
Pobiega
Pobiegaโ€ข17mo ago
new Car() isnt a variable new is a reserved keyword used to create objects
Soinagie
Soinagieโ€ข17mo ago
But you didnt even name it This object Its just a Car
Akseli
Akseliโ€ข17mo 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โ€ข17mo 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
Soinagieโ€ข17mo ago
I thought they were instances
circles.png
circles.pngโ€ข17mo ago
for example objects in a list can have no name but exist
Pobiega
Pobiegaโ€ข17mo ago
they are an instance is not the same thing as a variable
Soinagie
Soinagieโ€ข17mo ago
If they dont have names and variables whats the point of them? All of them are the same Then
Pobiega
Pobiegaโ€ข17mo ago
no they are not
circles.png
circles.pngโ€ข17mo ago
they might have different properties
Akseli
Akseliโ€ข17mo ago
you can have 5 different chairs with different properties like color and size but they are still all chairs
Pobiega
Pobiegaโ€ข17mo 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โ€ข17mo ago
they follow the same blueprint
Soinagie
Soinagieโ€ข17mo ago
Yeah and they're all different so they should have different names
Pobiega
Pobiegaโ€ข17mo ago
"names" isnt a thing
Soinagie
Soinagieโ€ข17mo ago
So you could separete them
circles.png
circles.pngโ€ข17mo ago
do you name your chairs?
Akseli
Akseliโ€ข17mo 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โ€ข17mo ago
i certainly dont name my chairs ๐Ÿ˜„
Akseli
Akseliโ€ข17mo ago
just like variables
Soinagie
Soinagieโ€ข17mo ago
I mean how will they know which chair am I talking about
Akseli
Akseliโ€ข17mo ago
you point to the chair
Soinagie
Soinagieโ€ข17mo ago
I give them names so other person know which one to pick up
circles.png
circles.pngโ€ข17mo ago
"the second chair from the left"
Soinagie
Soinagieโ€ข17mo ago
And objects are just "second from the left"?
circles.png
circles.pngโ€ข17mo ago
which can be "the second item in the list of chairs"
Pobiega
Pobiegaโ€ข17mo ago
kinda
Angius
Angiusโ€ข17mo ago
var secondChairFromTheLeft = new Chair(); Sure
Soinagie
Soinagieโ€ข17mo ago
Yeah you just named it
Akseli
Akseliโ€ข17mo 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
Soinagieโ€ข17mo ago
So I could use it now This specific object
Pobiega
Pobiegaโ€ข17mo 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
Soinagieโ€ข17mo ago
Before what?
Pobiega
Pobiegaโ€ข17mo ago
before "giving it a name"
Soinagie
Soinagieโ€ข17mo ago
Sorry I dont know anything about lists yet
Pobiega
Pobiegaโ€ข17mo ago
Look you're probably overthinking this by a lot
Soinagie
Soinagieโ€ข17mo ago
C# is object oriented language and I dont know what these objects are
Pobiega
Pobiegaโ€ข17mo 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โ€ข17mo ago
hes trolling
Soinagie
Soinagieโ€ข17mo ago
So for example car.(color) is an object? Or is it a type Or something else
Pobiega
Pobiegaโ€ข17mo ago
int car.(color) is not valid code so I cant tell
Soinagie
Soinagieโ€ข17mo ago
Oops Remove int
Pobiega
Pobiegaโ€ข17mo 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
Soinagieโ€ข17mo ago
Why would I make new objects?
Pobiega
Pobiegaโ€ข17mo 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โ€ข17mo ago
to structure data
Pobiega
Pobiegaโ€ข17mo ago
its how we write code if your application is a car inventory program isnt it useful to keep track of cars?
Soinagie
Soinagieโ€ข17mo ago
And I still dont know what that means
Servator
Servatorโ€ข17mo ago
@Soinagie Almost everything is an object in OOP programming
Pobiega
Pobiegaโ€ข17mo ago
you keep going around in circles
Servator
Servatorโ€ข17mo ago
Do you know why literally everything has ".ToString()" method ?
Soinagie
Soinagieโ€ข17mo ago
Wdym?
Akseli
Akseliโ€ข17mo 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โ€ข17mo ago
Pobiega
Pobiegaโ€ข17mo ago
I'm starting to agree with you
Servator
Servatorโ€ข17mo ago
Soinagie
Soinagieโ€ข17mo ago
If you're not willing to help you don't have to
circles.png
circles.pngโ€ข17mo ago
but whatever im kinda bored
Servator
Servatorโ€ข17mo ago
There is an "Object" class @Soinagie Every classes inherits that Object class
TheRanger
TheRangerโ€ข17mo 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โ€ข17mo ago
and the object class has a (virtual?) to string method
circles.png
circles.pngโ€ข17mo ago
which means all objects will have it
Soinagie
Soinagieโ€ข17mo ago
So all objects can be strings?
circles.png
circles.pngโ€ข17mo ago
yes
Pobiega
Pobiegaโ€ข17mo ago
no
circles.png
circles.pngโ€ข17mo ago
mb then
Pobiega
Pobiegaโ€ข17mo ago
all objects can be "turned into" strings
Servator
Servatorโ€ข17mo ago
all objects are not strings but all strings are objects not the other way around
Soinagie
Soinagieโ€ข17mo ago
I thought strings were a type
Pobiega
Pobiegaโ€ข17mo ago
a type. string is a type.
Servator
Servatorโ€ข17mo ago
classes are types there are primitive types and non-pritimitive types
Soinagie
Soinagieโ€ข17mo ago
So color is a non-primitive type
Pobiega
Pobiegaโ€ข17mo ago
string is a type, but an instance of a string is an object
Soinagie
Soinagieโ€ข17mo ago
So "hello world" is an object?
Pobiega
Pobiegaโ€ข17mo ago
yes
Servator
Servatorโ€ข17mo ago
It's a string yes
Akseli
Akseliโ€ข17mo 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โ€ข17mo ago
system.drawing.color is (i think)
Servator
Servatorโ€ข17mo ago
Usually you define an object with "new" keyword
MODiX
MODiXโ€ข17mo 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โ€ข17mo ago
But C# has a feature called implicit and explicit operator compiler uses that to create a string
Soinagie
Soinagieโ€ข17mo ago
So if I do int x=100 then x is an object?
Akseli
Akseliโ€ข17mo ago
stop introducing more and more unrelated things, the valid explanation for objects is here ^
Pobiega
Pobiegaโ€ข17mo 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
Soinagieโ€ข17mo ago
Simple question do I need to know what objects are?
circles.png
circles.pngโ€ข17mo ago
yes definitely
Pobiega
Pobiegaโ€ข17mo ago
not to the level of understanding you seem to seek
Soinagie
Soinagieโ€ข17mo ago
Then if I cant use objects why do I need to know about them
Pobiega
Pobiegaโ€ข17mo ago
who said you cant use them
Soinagie
Soinagieโ€ข17mo ago
.
Pobiega
Pobiegaโ€ข17mo ago
var x = new Car(); is using an object its just that x isnt the object its a variable pointing to the object
Soinagie
Soinagieโ€ข17mo ago
But this object was never created
Servator
Servatorโ€ข17mo ago
[declaretation] = [assignment] [type] [name] = [value]
Soinagie
Soinagieโ€ข17mo ago
I cant refer to something that doesnt exist
Pobiega
Pobiegaโ€ข17mo ago
new Car() creates it
Servator
Servatorโ€ข17mo ago
It creates it ^^
Soinagie
Soinagieโ€ข17mo ago
So now x is an instance of car?
Pobiega
Pobiegaโ€ข17mo ago
no, its a variable pointing to an instance of Car
Servator
Servatorโ€ข17mo ago
Servator
Servatorโ€ข17mo ago
yes exactly
Pobiega
Pobiegaโ€ข17mo ago
x is never anything but a variable
Soinagie
Soinagieโ€ข17mo ago
And whats that instance? Of car
Pobiega
Pobiegaโ€ข17mo ago
Ok you are trolling
circles.png
circles.pngโ€ข17mo ago
a lot of ones and zeros
Pobiega
Pobiegaโ€ข17mo ago
pick up two pens. they are two different instances of "Pen"
Soinagie
Soinagieโ€ข17mo ago
Yes they are So theyre 2 objects
Pobiega
Pobiegaโ€ข17mo ago
sure
Soinagie
Soinagieโ€ข17mo ago
Then where did you use an object? If x isnt an object
Pobiega
Pobiegaโ€ข17mo ago
creating it is using it
Soinagie
Soinagieโ€ข17mo ago
And car is class
Pobiega
Pobiegaโ€ข17mo ago
x.Color is using an object etc
circles.png
circles.pngโ€ข17mo ago
class is the class in classify or classification
Pobiega
Pobiegaโ€ข17mo ago
just because x itself isnt the object doesnt mean you cant interact with the object with the variable
Soinagie
Soinagieโ€ข17mo ago
And car is this object? And its name is x?
Pobiega
Pobiegaโ€ข17mo ago
go away troll
Soinagie
Soinagieโ€ข17mo ago
Or is it its value Tbh I dont know the differnce
Servator
Servatorโ€ข17mo ago
x just refers to an object real object is new Car()
Soinagie
Soinagieโ€ข17mo ago
So its it name
Servator
Servatorโ€ข17mo ago
[declaretation] = [assignment] [type] [name] = [value]
Soinagie
Soinagieโ€ข17mo ago
And you can refer to that specific object
Servator
Servatorโ€ข17mo ago
yes
Pobiega
Pobiegaโ€ข17mo ago
(simplification)
Akseli
Akseliโ€ข17mo ago
imagine doing this to an actual teacher in school holy shit i wish i back in primary school
Servator
Servatorโ€ข17mo ago
I wish i was curious like him when i start coding
Soinagie
Soinagieโ€ข17mo ago
Wdym by that?
Servator
Servatorโ€ข17mo 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
Soinagieโ€ข17mo ago
Both x=10 and 10=x mean the same
Servator
Servatorโ€ข17mo ago
no = is used for assignment in programming languages (most of them) not for comparison
Soinagie
Soinagieโ€ข17mo ago
Yeah I assign value 10 to x
Servator
Servatorโ€ข17mo ago
= means literally get the value (right side of ๐Ÿ™‚ and put it in left side of =
MODiX
MODiXโ€ข17mo 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
Soinagieโ€ข17mo ago
So x isnt 10 but 10 is x?
Servator
Servatorโ€ข17mo ago
what is 10 ?
Soinagie
Soinagieโ€ข17mo ago
Int
Servator
Servatorโ€ข17mo ago
Servator
Servatorโ€ข17mo ago
but "10" doesn't refer to a variable
circles.png
circles.pngโ€ข17mo ago
left side is always the target
Servator
Servatorโ€ข17mo 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โ€ข17mo ago
a human's name can be Soinagie, but a Soinagie's Name can't be a human
Soinagie
Soinagieโ€ข17mo ago
So I assign value of right thing to the left thing
Servator
Servatorโ€ข17mo ago
yes
Soinagie
Soinagieโ€ข17mo ago
And then x is a object new Car
Servator
Servatorโ€ข17mo ago
yes
Pobiega
Pobiegaโ€ข17mo ago
(no) if x was the object, then how on earth would var y = x; be valid?
Soinagie
Soinagieโ€ข17mo ago
And new always means I create an object
TheRanger
TheRangerโ€ข17mo ago
var tails = new Fox();
var miles = tails;
var tails = new Fox();
var miles = tails;
Pobiega
Pobiegaโ€ข17mo ago
there is still only 1 object
TheRanger
TheRangerโ€ข17mo ago
miles and tails refer to the same fox
Soinagie
Soinagieโ€ข17mo ago
Then whats the point of keyword "new"? Yeah and you can use both interchangibly
Pobiega
Pobiegaโ€ข17mo ago
but they are not the object they are references to the same object they are not "the name of the object"
TheRanger
TheRangerโ€ข17mo ago
in a sonic game, when you start a new level, they do new Sonic(); and stuff
Soinagie
Soinagieโ€ข17mo ago
Reference is a name You refer to me by using my name
Pobiega
Pobiegaโ€ข17mo ago
so say reference dont say name
Servator
Servatorโ€ข17mo ago
We access references with name
TheRanger
TheRangerโ€ข17mo ago
var soinagie = new Human();
soinagie.Jump();
var soinagie = new Human();
soinagie.Jump();
Soinagie
Soinagieโ€ข17mo ago
Then this specific new human named soinagie jumps
TheRanger
TheRangerโ€ข17mo ago
yes
Soinagie
Soinagieโ€ข17mo ago
And soinagie is an instance of class human
TheRanger
TheRangerโ€ข17mo ago
yes
Soinagie
Soinagieโ€ข17mo ago
Or type Class or type?
TheRanger
TheRangerโ€ข17mo ago
a class is a type
Soinagie
Soinagieโ€ข17mo ago
They're the same or is it like square and rectangle?
Pobiega
Pobiegaโ€ข17mo ago
all classes are types, not all types are classes
TheRanger
TheRangerโ€ข17mo ago
yes, a class is one of the subcategories of a type
Soinagie
Soinagieโ€ข17mo ago
So a type is a kind of value (like color) and class is a template for objects with the same type
TheRanger
TheRangerโ€ข17mo ago
not sure what you mean a class is a reference type
Soinagie
Soinagieโ€ข17mo ago
Reference to what?
TheRanger
TheRangerโ€ข17mo 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
Soinagieโ€ข17mo ago
Yeah
TheRanger
TheRangerโ€ข17mo ago
so the same fox will jump twice
Soinagie
Soinagieโ€ข17mo ago
I get it But class is a reference to what
Pobiega
Pobiegaโ€ข17mo ago
its not a reference, its a "reference type"
Soinagie
Soinagieโ€ข17mo ago
So its a kind of specific type of value? Like color?
TheRanger
TheRangerโ€ข17mo ago
its a type of reference type of value is something else
Soinagie
Soinagieโ€ข17mo ago
Then is it reference type or type of refernce?
TheRanger
TheRangerโ€ข17mo ago
thats the same thing
Soinagie
Soinagieโ€ข17mo ago
And what is it? Its a template for creating objects
TheRanger
TheRangerโ€ข17mo ago
yeah, u can have a single object, and multiple variables refer to the same object, like tails and fox value types cant
Soinagie
Soinagieโ€ข17mo ago
Isnt refering and containg value essentialy the same? You use that value in both cases
TheRanger
TheRangerโ€ข17mo ago
idk i dont really focus on these terms
Soinagie
Soinagieโ€ข17mo ago
You just gave me a link to refernce types which separetes these two
TheRanger
TheRangerโ€ข17mo ago
integer is a value type
Soinagie
Soinagieโ€ข17mo ago
Tails is a refernce type then?
TheRanger
TheRangerโ€ข17mo ago
Fox is
Soinagie
Soinagieโ€ข17mo ago
And tails is...
TheRanger
TheRangerโ€ข17mo ago
a variable
Soinagie
Soinagieโ€ข17mo ago
What
TheRanger
TheRangerโ€ข17mo ago
that refers to the object fox you just created
Soinagie
Soinagieโ€ข17mo ago
I refers to fox Both refer to fox
Pobiega
Pobiegaโ€ข17mo ago
they both refer to a fox, the same fox. they are not references to the class itself
Soinagie
Soinagieโ€ข17mo ago
Then tails isnt a variable, its a reference
Akseli
Akseliโ€ข17mo ago
this is still going? cmon guys
TheRanger
TheRangerโ€ข17mo ago
tails IS a variable
Soinagie
Soinagieโ€ข17mo ago
Why?
Akseli
Akseliโ€ข17mo ago
tails is a reference
Soinagie
Soinagieโ€ข17mo ago
. .
TheRanger
TheRangerโ€ข17mo ago
or a reference variable, i guess u can call it that
Akseli
Akseliโ€ข17mo ago
its both a variable and a reference reference type and a reference are 2 seperate things
Soinagie
Soinagieโ€ข17mo ago
And same goes for miles
TheRanger
TheRangerโ€ข17mo ago
yes, reference, and reference type are 2 different things
Soinagie
Soinagieโ€ข17mo ago
What๐Ÿ˜ญ
streepje8
streepje8โ€ข17mo ago
Type = A Car In General Object = A Specific Car Variable = That Car Over There
Soinagie
Soinagieโ€ข17mo ago
Isnt that car over there also a specific car? I dont think so
streepje8
streepje8โ€ข17mo ago
Its not about the car, its about the pointing to a car a variable is the thing that points to it
Soinagie
Soinagieโ€ข17mo ago
Yeah you point to a specific car
Akseli
Akseliโ€ข17mo ago
insanetrollface
TheRanger
TheRangerโ€ข17mo 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
Soinagieโ€ข17mo ago
In both cases
streepje8
streepje8โ€ข17mo ago
Ok no the object is what you are pointing to and you are the variable you are not a car
Soinagie
Soinagieโ€ข17mo ago
How am I relevant?
streepje8
streepje8โ€ข17mo ago
If you are pointing to a car you are a sort of variable
Akseli
Akseliโ€ข17mo ago
one person go at a time and try to explain it, so there wont be any conflicts introduced to his mind
streepje8
streepje8โ€ข17mo 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โ€ข17mo ago
we've been trying to explain that for the last 2 hours
Dusty
Dustyโ€ข17mo ago
and it's very entertaining (no offense with that, I like it that you guys try your best)
Akseli
Akseliโ€ข17mo ago
he is trolling but i enjoy watching it
Soinagie
Soinagieโ€ข17mo ago
They* And Im not I just want to understand that
streepje8
streepje8โ€ข17mo ago
Im not sure but i dont want to be rude to them if im wrong
Dusty
Dustyโ€ข17mo ago
Idk actually, I've seen other people that don't understand it for weeks until a bit of practical experience
streepje8
streepje8โ€ข17mo ago
Ill just leave this convo and read back what came out of it haha
Akseli
Akseliโ€ข17mo ago
scroll up and you will see
Soinagie
Soinagieโ€ข17mo ago
Ok @implicit electron can you explain to me varaiables and objects then?
Dusty
Dustyโ€ข17mo ago
If you wanna understand it go and write some programs, after a few days you'll get a better understanding ?
TheRanger
TheRangerโ€ข17mo ago
ur an object of human, Soinagie is ur variable, when someone calls ur name, we know we are refering to you
Soinagie
Soinagieโ€ข17mo 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โ€ข17mo ago
I can't wait for the confusion when they figure out that an object's type is object
TheRanger
TheRangerโ€ข17mo ago
careful, int isn't a reference type 10 isn't an object
Soinagie
Soinagieโ€ข17mo ago
X is
Dusty
Dustyโ€ข17mo ago
you need to explain the difference between reference and value types
Soinagie
Soinagieโ€ข17mo ago
Ok @implicit electron only talk for now please
TheRanger
TheRangerโ€ข17mo 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
Soinagieโ€ข17mo ago
I dont know the difference
TheRanger
TheRangerโ€ข17mo ago
take baby steps, fully understand one of them first
Soinagie
Soinagieโ€ข17mo 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โ€ข17mo ago
well you have some idea about reference types right? might need to continue to finish learning that first
Soinagie
Soinagieโ€ข17mo ago
I dont think I have
TheRanger
TheRangerโ€ข17mo ago
i gave you an example of miles and tails, what did you not understand from that
Soinagie
Soinagieโ€ข17mo ago
Then whats the difference between variable and refernce type?
TheRanger
TheRangerโ€ข17mo ago
Human is a reference type
Soinagie
Soinagieโ€ข17mo ago
I thought human was a class
TheRanger
TheRangerโ€ข17mo ago
well, class is a reference type same meaning we did mention that above, i think
Soinagie
Soinagieโ€ข17mo ago
And what specifically is a refence type?
TheRanger
TheRangerโ€ข17mo ago
didnt we just explain that?
Soinagie
Soinagieโ€ข17mo ago
.
TheRanger
TheRangerโ€ข17mo ago
thats a different issue
Dusty
Dustyโ€ข17mo ago
explaining that is way easier than the concept of reference types though
Soinagie
Soinagieโ€ข17mo ago
Int is a type
Dusty
Dustyโ€ข17mo ago
yes
TheRanger
TheRangerโ€ข17mo ago
Int is a type, but not a reference type its a Value type
Soinagie
Soinagieโ€ข17mo ago
And reference types are made up types Like color
Pobiega
Pobiegaโ€ข17mo 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
Soinagieโ€ข17mo ago
Why is programming so hard to learn
TheRanger
TheRangerโ€ข17mo ago
depends on the person
TotallyJustin
TotallyJustinโ€ข17mo ago
Itโ€™s not
Dusty
Dustyโ€ข17mo ago
It's all learning by doing imho
Soinagie
Soinagieโ€ข17mo ago
I mean car(color)
Pobiega
Pobiegaโ€ข17mo ago
I would highly recommend you get started programming, instead of wondering on the theoretical definition of every single term
Soinagie
Soinagieโ€ข17mo ago
There is no default color type in C# You create it So its made up
Pobiega
Pobiegaโ€ข17mo 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
Soinagieโ€ข17mo ago
And its a variable or refernce type? The code you just made
Pobiega
Pobiegaโ€ข17mo ago
thats an enum, its neither its a value type
Thinker
Thinkerโ€ข17mo 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
Soinagieโ€ข17mo ago
Then how is it relevant?
Akseli
Akseliโ€ข17mo ago
its not an assumption
Pobiega
Pobiegaโ€ข17mo ago
because you just claimed all "made up types" are reference types which they are not
Thinker
Thinkerโ€ข17mo ago
yes it is, where did they state they are trolling
TotallyJustin
TotallyJustinโ€ข17mo 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โ€ข17mo 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โ€ข17mo ago
read the convo from start...
Thinker
Thinkerโ€ข17mo ago
700 messages?
MODiX
MODiXโ€ข17mo 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โ€ข17mo ago
you only need to read the first 100 to see it
TheRanger
TheRangerโ€ข17mo ago
@Soinagie tell me the difference between the 2 codes i posted above
Thinker
Thinkerโ€ข17mo ago
if you don't want to help then just... leave this thread
Soinagie
Soinagieโ€ข17mo ago
Theres a class and struct But I dont know how they're different
TheRanger
TheRangerโ€ข17mo ago
what about the Console output? why did one print 0 , and the other printed 10?
Soinagie
Soinagieโ€ข17mo ago
Bc fox wasnt a class? In 1st one
TheRanger
TheRangerโ€ข17mo ago
yeah, but why
Soinagie
Soinagieโ€ข17mo ago
I dont know
TheRanger
TheRangerโ€ข17mo ago
simple this
var miles = tails;
var miles = tails;
Thinker
Thinkerโ€ข17mo ago
I personally can't find anything that suggests anything other than that this person is just trying to understand.
TheRanger
TheRangerโ€ข17mo ago
cloned tails so now you have 2 foxes
Soinagie
Soinagieโ€ข17mo ago
Cloned?
TheRanger
TheRangerโ€ข17mo ago
like, copied
Soinagie
Soinagieโ€ข17mo ago
Where
TheRanger
TheRangerโ€ข17mo ago
here
Soinagie
Soinagieโ€ข17mo ago
Miles and tails arent foxes
Akseli
Akseliโ€ข17mo ago
just try to help him, im not bothered anymore
TheRanger
TheRangerโ€ข17mo ago
they are
Soinagie
Soinagieโ€ข17mo ago
They're a value for a fox Or a refernce Or something else I dont know
TheRanger
TheRangerโ€ข17mo ago
since fox is a struct in the first code, the variable isnt a reference anymore
Soinagie
Soinagieโ€ข17mo ago
I dont know what a struct is really
TheRanger
TheRangerโ€ข17mo 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
Soinagieโ€ข17mo ago
And why does it work with class fox? What does that class do?
TheRanger
TheRangerโ€ข17mo ago
because class is a reference type, struct is a value type many variables can refer to the same object, struct cant
Soinagie
Soinagieโ€ข17mo ago
Why does it matter if it was copied?
TheRanger
TheRangerโ€ข17mo ago
depends on the programmer
Soinagie
Soinagieโ€ข17mo ago
If it cant reference it Since its not a class
TheRanger
TheRangerโ€ข17mo ago
do you want it to be copied or not
Soinagie
Soinagieโ€ข17mo ago
No but it still doesmr matter It cant even get access to it
TheRanger
TheRangerโ€ข17mo ago
if int is a class
Soinagie
Soinagieโ€ข17mo ago
You just said that int isnt a class
TheRanger
TheRangerโ€ข17mo 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
Soinagieโ€ข17mo ago
If what?
TheRanger
TheRangerโ€ข17mo ago
sounds like ur not good at english, no offense so i believe its hard to communicate with you
Soinagie
Soinagieโ€ข17mo ago
Ok but what did you mean with that?
MODiX
MODiXโ€ข17mo 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โ€ข17mo ago
note how he said if
TheRanger
TheRangerโ€ข17mo 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
Soinagieโ€ข17mo ago
There are no refernces here
Pobiega
Pobiegaโ€ข17mo ago
thats what the "if" was for if int was a reference type, it would be impractical
Soinagie
Soinagieโ€ข17mo ago
Where is the "if" in this example? What even does "if" has to do with any of it?
Pobiega
Pobiegaโ€ข17mo ago
if int was a reference type, changing 5000 in one place would change it in all the places
Soinagie
Soinagieโ€ข17mo ago
Isnt it salary=5000
Pobiega
Pobiegaโ€ข17mo ago
if as in the english word if, not the keyword.
Soinagie
Soinagieโ€ข17mo ago
And you change it to salary =10000 Then is it keyword or english word?
TheRanger
TheRangerโ€ข17mo ago
i was speaking about the contents of the number itself, not letting the variable point to another number
Soinagie
Soinagieโ€ข17mo ago
Number is the content 10 is 10 Theres nothing more to it How does variable "point to"?
Pobiega
Pobiegaโ€ข17mo ago
with value types, they dont with reference types, thats how programming with reference types work
TheRanger
TheRangerโ€ข17mo ago
say for example you have defined a struct color
Soinagie
Soinagieโ€ข17mo ago
So strings and classes are reference types, rest of them are value types?
MODiX
MODiXโ€ข17mo 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โ€ข17mo ago
tell me why that printed 255
MODiX
MODiXโ€ข17mo 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
Soinagieโ€ข17mo ago
You asked me similiar question while ago and I still don't know
TheRanger
TheRangerโ€ข17mo ago
and why that printed 64 because one is struct(a value type) and other is class(a reference type)
Soinagie
Soinagieโ€ข17mo ago
and I dont know the difference
Pobiega
Pobiegaโ€ข17mo ago
that is the difference
TheRanger
TheRangerโ€ข17mo 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
Soinagieโ€ข17mo ago
but another color what defined as 255
TheRanger
TheRangerโ€ข17mo ago
wdym
Soinagie
Soinagieโ€ข17mo ago
anotherColor = color
TheRanger
TheRangerโ€ข17mo ago
in which code?
Soinagie
Soinagieโ€ข17mo ago
color.red= 0 in 1st
TheRanger
TheRangerโ€ข17mo ago
whjat about it?
Soinagie
Soinagieโ€ข17mo ago
so it should print 0
TheRanger
TheRangerโ€ข17mo ago
why should it, i set color's red to be 0, not anotherColor's red
Soinagie
Soinagieโ€ข17mo ago
yeah and anotherColor = color so they have the same value
TheRanger
TheRangerโ€ข17mo ago
it got copied thats how value types work
Soinagie
Soinagieโ€ข17mo ago
I still dont know what you mean by that
TheRanger
TheRangerโ€ข17mo ago
when u do anotherColor = color its like u did anotherColor = new Color { red = 255 };
Soinagie
Soinagieโ€ข17mo ago
yeah they both are 255
TheRanger
TheRangerโ€ข17mo ago
yeah, however in the first one, i only changed color's red to be 0, anotherColor's red stayed the same
Soinagie
Soinagieโ€ข17mo ago
but they're now the same thing now essentialy they have the same values
TheRanger
TheRangerโ€ข17mo ago
at first yes, but changed one of their reds
Soinagie
Soinagieโ€ข17mo ago
but you did the same with class color and it came out different it shouldn't have
TheRanger
TheRangerโ€ข17mo ago
exactly why not?
Soinagie
Soinagieโ€ข17mo ago
bc you set anotherColor as 255
TheRanger
TheRangerโ€ข17mo ago
because they are the same object
Soinagie
Soinagieโ€ข17mo ago
and in struct they're not?
TheRanger
TheRangerโ€ข17mo ago
no it got copied like i said
Soinagie
Soinagieโ€ข17mo ago
copying doesnt erase a value
TheRanger
TheRangerโ€ข17mo ago
it didnt erase it where did it erase it?
Soinagie
Soinagieโ€ข17mo ago
in color.red = 0 but it still printed 255
TheRanger
TheRangerโ€ข17mo ago
i printed anotherColor's red not color's red
Soinagie
Soinagieโ€ข17mo ago
and same goes for 2nd code you did the same thing
TheRanger
TheRangerโ€ข17mo ago
yes, because anotherColor and color refer to the same object in the 2nd code
Soinagie
Soinagieโ€ข17mo ago
then why use struct class?
TheRanger
TheRangerโ€ข17mo ago
whats a struct class
Soinagie
Soinagieโ€ข17mo ago
public struct Color
TheRanger
TheRangerโ€ข17mo ago
to copy data without affecting the original like u see above
Soinagie
Soinagieโ€ข17mo ago
I still don't understand this copying thing
TheRanger
TheRangerโ€ข17mo 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
Soinagieโ€ข17mo ago
maybe, kinda?
TheRanger
TheRangerโ€ข17mo ago
$refvsvalue
Soinagie
Soinagieโ€ข17mo 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โ€ข17mo 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โ€ข17mo 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
Soinagieโ€ข17mo ago
if it copies the value shouldn't it then be 255? for 1st one
TheRanger
TheRangerโ€ข17mo ago
who should be 255?
Soinagie
Soinagieโ€ข17mo ago
bc it copied the value like you said
TheRanger
TheRangerโ€ข17mo ago
color or anotherColor?
Soinagie
Soinagieโ€ข17mo ago
anotherColor got value from color which was 255
TheRanger
TheRangerโ€ข17mo ago
yeah, it did
Soinagie
Soinagieโ€ข17mo ago
then if its got that value it should print it
TheRanger
TheRangerโ€ข17mo ago
it did
Soinagie
Soinagieโ€ข17mo 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โ€ข17mo ago
MODiX
MODiXโ€ข17mo 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
Soinagieโ€ข17mo ago
but you set anotherColor = color so they're the same they have the same value
TheRanger
TheRangerโ€ข17mo ago
nope, it got copied theyre not the same
Soinagie
Soinagieโ€ข17mo ago
= means equals
TheRanger
TheRangerโ€ข17mo ago
yeah ur point?
Soinagie
Soinagieโ€ข17mo ago
that equals means these things are the same sorry if Im annoying you
TheRanger
TheRangerโ€ข17mo ago
2 different objects that have the same red 255
Soinagie
Soinagieโ€ข17mo ago
x = 5, that means x is equal 5 and nothing else
TheRanger
TheRangerโ€ข17mo ago
ok in math u have x = 5 and y = x now y and x are 5 right?
Soinagie
Soinagieโ€ข17mo ago
it cant equal x = 6 right
TheRanger
TheRangerโ€ข17mo ago
what if lets say 5 = 20 is a thing
Soinagie
Soinagieโ€ข17mo ago
it cant be how?
Servator
Servatorโ€ข17mo ago
= for assignment == for comparison we talked about this :/
TheRanger
TheRangerโ€ข17mo ago
they arent asking for comparison atm
Soinagie
Soinagieโ€ข17mo ago
you cant assign a number other number
TheRanger
TheRangerโ€ข17mo ago
mathematically u cant yeah i was giving an example ok so do u know pie 3.14?
Soinagie
Soinagieโ€ข17mo ago
yeah
TheRanger
TheRangerโ€ข17mo ago
x = pie and y = pie correct?
Soinagie
Soinagieโ€ข17mo ago
yes
TheRanger
TheRangerโ€ข17mo ago
what if i changed pie to 9 instead of 3.14
Soinagie
Soinagieโ€ข17mo ago
its a constant
TheRanger
TheRangerโ€ข17mo ago
i know but lets say we can change it
Soinagie
Soinagieโ€ข17mo ago
ok?
TheRanger
TheRangerโ€ข17mo ago
programatically what would the value of x and y be?
Soinagie
Soinagieโ€ข17mo ago
9
TheRanger
TheRangerโ€ข17mo ago
if pie is a class then yes, if its a struct, then no here is a better example
Soinagie
Soinagieโ€ข17mo 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โ€ข17mo 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โ€ข17mo 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
Soinagieโ€ข17mo ago
why did you do new Pie()?
TheRanger
TheRangerโ€ข17mo ago
to initialize it
Soinagie
Soinagieโ€ข17mo ago
cant you do just Pie?
TheRanger
TheRangerโ€ข17mo ago
no
Soinagie
Soinagieโ€ข17mo ago
so I call all my methods with new?
TheRanger
TheRangerโ€ข17mo ago
?
Soinagie
Soinagieโ€ข17mo ago
Pie is a method right?
Anton
Antonโ€ข17mo ago
pie is not a method
Servator
Servatorโ€ข17mo ago
Your are missing the main point @Soinagie
TheRanger
TheRangerโ€ข17mo ago
which Pie, the one next to new or next to class/struct?
Servator
Servatorโ€ข17mo ago
He changed x's Value
Anton
Antonโ€ข17mo ago
you're referring to the constructor probably
Servator
Servatorโ€ข17mo ago
but Y's value is changed too Why ? Focus here
Servator
Servatorโ€ข17mo ago
Soinagie
Soinagieโ€ข17mo ago
bc x and y in reference type are treated as the same things?
TheRanger
TheRangerโ€ข17mo ago
yes
Soinagie
Soinagieโ€ข17mo ago
well thats I understand but it shouldn't apply a completly different logic to a different type
TheRanger
TheRangerโ€ข17mo ago
what?
Soinagie
Soinagieโ€ข17mo ago
I mean value type I dont understand value type
TheRanger
TheRangerโ€ข17mo ago
not sure what u mean
Servator
Servatorโ€ข17mo ago
It gets the all properties yet values are different values not bound to anything
Soinagie
Soinagieโ€ข17mo ago
but theres "=" can we do another mathematical allegory? for value type?
TheRanger
TheRangerโ€ข17mo ago
not sure what that means
Soinagie
Soinagieโ€ข17mo ago
we did pie for refernce type
TheRanger
TheRangerโ€ข17mo ago
yes
Soinagie
Soinagieโ€ข17mo ago
what I mean is could you elaborate why "no"?
TheRanger
TheRangerโ€ข17mo ago
that was an answer to ur question
Soinagie
Soinagieโ€ข17mo ago
if pie is 9 and pie=x=y then both are 9s
TheRanger
TheRangerโ€ข17mo ago
pie=x=y ? what?
Soinagie
Soinagieโ€ข17mo ago
.
TheRanger
TheRangerโ€ข17mo ago
if its a class or a struct?
Soinagie
Soinagieโ€ข17mo ago
we did reference
TheRanger
TheRangerโ€ข17mo ago
yeah
Soinagie
Soinagieโ€ข17mo ago
class and I would pls like to do struct
TheRanger
TheRangerโ€ข17mo ago
what about x = pie ?
Soinagie
Soinagieโ€ข17mo ago
what about it?
TheRanger
TheRangerโ€ข17mo ago
u pinged me for this
Soinagie
Soinagieโ€ข17mo ago
yeah you explained reference type right?
TheRanger
TheRangerโ€ข17mo ago
yes
Soinagie
Soinagieโ€ข17mo ago
but for value type you just said "it doesnt happen"
TheRanger
TheRangerโ€ข17mo ago
where did i say that what exactly doesn't happen ?
Soinagie
Soinagieโ€ข17mo ago
. its not a 9 if its a struc
TheRanger
TheRangerโ€ข17mo ago
heres a better example
MODiX
MODiXโ€ข17mo 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โ€ข17mo ago
what did u notice in this?
Soinagie
Soinagieโ€ข17mo ago
that y = x but they both show different values
TheRanger
TheRangerโ€ข17mo ago
yeah
Soinagie
Soinagieโ€ข17mo ago
and thats my problem
TheRanger
TheRangerโ€ข17mo ago
it copied it
Soinagie
Soinagieโ€ข17mo ago
if it copied it then shouldn't it be the same?
TheRanger
TheRangerโ€ข17mo ago
no, a copy is a copy like u copy a file
Soinagie
Soinagieโ€ข17mo ago
yeah its the same file with same value
TheRanger
TheRangerโ€ข17mo ago
no, 2 different files, have equal data
Soinagie
Soinagieโ€ข17mo ago
I means their contents are the same
TheRanger
TheRangerโ€ข17mo ago
yes if you modified one of the contents of the first file would it also get modified in the 2nd file?
Soinagie
Soinagieโ€ข17mo ago
no
TheRanger
TheRangerโ€ข17mo ago
exactly thats how struct works
Soinagie
Soinagieโ€ข17mo ago
wait so it creates a copy and then modifies it?
TheRanger
TheRangerโ€ข17mo ago
yes
Soinagie
Soinagieโ€ข17mo ago
and original value of 3.14 is never changed
TheRanger
TheRangerโ€ข17mo ago
the one that is stored in y yes
Soinagie
Soinagieโ€ข17mo ago
then what does var y = x do?
TheRanger
TheRangerโ€ข17mo 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
Soinagieโ€ข17mo ago
y is the original and x is the copy of it
TheRanger
TheRangerโ€ข17mo ago
other way x is the original, y is the copy be advised
Soinagie
Soinagieโ€ข17mo ago
but you assigned 9 to x
TheRanger
TheRangerโ€ข17mo ago
var y = x copies it if its a struct
Soinagie
Soinagieโ€ข17mo ago
shouldn't then pie also be 9? if its an original
TheRanger
TheRangerโ€ข17mo ago
ive never changed the value of pie
Soinagie
Soinagieโ€ข17mo ago
so you created pie assigned it 3.14 created x assigned it 9 thats a version of pie
TheRanger
TheRangerโ€ข17mo ago
yes
Soinagie
Soinagieโ€ข17mo ago
and made y thats a copy of x
TheRanger
TheRangerโ€ข17mo ago
i made y thats a copy of x before i changed x's value
Soinagie
Soinagieโ€ข17mo ago
oohh right so if it'd be lower both'd be 9 right?
MODiX
MODiXโ€ข17mo 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โ€ข17mo ago
yes
Soinagie
Soinagieโ€ข17mo ago
ok Im kinda getting it so "=" in value types copies variables
TheRanger
TheRangerโ€ข17mo ago
pretty much
Soinagie
Soinagieโ€ข17mo ago
and my default thinking of "=" comes from refernce type
TheRanger
TheRangerโ€ข17mo 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
Soinagieโ€ข17mo 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โ€ข17mo ago
i never said ur trolling class in C++ isnt a reference type
Soinagie
Soinagieโ€ข17mo ago
sorry Im not planning on C++
TheRanger
TheRangerโ€ข17mo ago
its just struct with public and private access modifiers
Soinagie
Soinagieโ€ข17mo ago
ok so for c# this * doesnt't apply?
TheRanger
TheRangerโ€ข17mo ago
only in unsafe context which is very dangerous, can freeze ur pc if you used it wrong
Soinagie
Soinagieโ€ข17mo ago
ok I just won't use * then
TheRanger
TheRangerโ€ข17mo ago
ull probably need it sometime in the future
Soinagie
Soinagieโ€ข17mo ago
I dont want my pc frozen
TheRanger
TheRangerโ€ข17mo 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
Soinagieโ€ข17mo 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โ€ข17mo ago
np
Monsieur Wholesome
Monsieur Wholesomeโ€ข17mo ago
what the
Monsieur Wholesome
Monsieur Wholesomeโ€ข17mo ago
lordnaseMonkas
TheRanger
TheRangerโ€ข17mo ago
well its now 1087 trollface
Monsieur Wholesome
Monsieur Wholesomeโ€ข17mo ago
will we hit 1k?
TheRanger
TheRangerโ€ข17mo ago
we already did
Angius
Angiusโ€ข17mo ago
๐ŸŽ‰ Here's to another 1000!
arion
arionโ€ข17mo ago
Ok can at least say its thorough
mtreit
mtreitโ€ข17mo ago
PauseChamp we conclude what an object is?
TheRanger
TheRangerโ€ข17mo ago
i think so
Pobiega
Pobiegaโ€ข17mo 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โ€ข17mo ago
just a little bit
Servator
Servatorโ€ข17mo ago
He try to learn fast (which is bad)
Soinagie
Soinagieโ€ข17mo ago
Im not trying to learn fast, I just want to understand bare basics
Thinker
Thinkerโ€ข17mo 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
Soinagieโ€ข17mo ago
Sorry
Servator
Servatorโ€ข17mo 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โ€ข17mo 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
More Posts
โ” ASP.NET CALLBACKhello i've got a callback with a JWS signature how would i add a new controller to the site to handlโ” error when converting string to long```cs System.FormatException: Input string was not in a correct format. ``` you can see on image frxamarin errori get this error running xamarin android app on windows running same project on macos worksโ” Tell DbProviderFactory what connection string to use not working?```DbProviderFactories.RegisterFactory("System.Data.MySql", MySqlConnectorFactory.Instance); serviceโ” How can i calculate a rotation float from a direction vector?i know this might not be the correct place to ask such a question, but i figured such a large numberโ” How can I better understand the concepts of unit of work and repository pattern in C# .NET 7?I am seeking assistance in understanding the unit of work and repository pattern in C#.NET7. While Iโ” Help with a unity Inventoryim making an Inventory for my unity game and im getting this CS1061 error, i Know what the error is,โ” Running an awaitable async Task, but forcing it to run on a specific thread (main thread).Hi everyone, I'm doing some work in Unity and am having an issue where some of the code that I want โ” Help connect VS-Code to Unity and Simplify running programI want to connect Unity and VS code Also ive done it before but i want to simplify how you run the โ” Issue with unit testing and projects not startingI'm writing up tests for my controller, but I need to grab an access token for authorization to do a