Object 2 | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Object 2

"The this refers to the current instance of the class, meaning it refers to the current object. One of the common uses of this is to distinguish class members from other data, such as local or formal parameters of a method: class Person { private string name; public Person(string name) { this.name = name; } } 💢Another common use of this is for passing the current instance to a method as parameter: ShowPersonInfo(this);"💢 According to this "private string name;" is an object. 😐? right???

21st Mar 2017, 12:56 PM
Amir Hossein Karimi
Amir Hossein Karimi - avatar
3 Answers
+ 2
OOP == Object Oriented Programming
21st Mar 2017, 4:24 PM
Ettienne Gilbert
Ettienne Gilbert - avatar
+ 1
An object is an instance of a class. And since string is a class type, name is indeed an object (it is an instance of class type string). So 'name' is an object that is a member of class type Person. And when an object of class type Person is created, that object will contain a member object called 'name'. An object inside another object.... This is part of encapsulation, one of the fundamental ideas in OOP.
21st Mar 2017, 1:17 PM
Ettienne Gilbert
Ettienne Gilbert - avatar
0
I forgot that strings are objects, and I had this single minded idea that objects are merely defined in the Main method. I must confess, Although your explanation was so confusing to me due to my inexperience, but I understood completely (after reading it 6times, and trying to make sense 😅) thank you very much Ettienne, but what was an OOP?
21st Mar 2017, 1:28 PM
Amir Hossein Karimi
Amir Hossein Karimi - avatar