Question Dot notation .Equals

Tomuks69

New member
Joined
Feb 22, 2021
Messages
2
Programming Experience
1-3
I was wondering how does this code of line works:
Sample:
var a = x.Equals(y) returns true

Isnt it like x is being passed as variable something like:

a = EqualsCustom(x, y)
Public bool EqualsCustom = {
//Some comparison code..
}
I am just wondering how this dot notation works other than accessing some members?
 

Skydiver

Staff member
Joined
Apr 6, 2019
Messages
2,583
Location
Chesapeake, VA
Programming Experience
10+
Yes, if you were looking at this as a old fashioned C programmer. But in modern object oriented eyes, no.
 

JohnH

C# Forum Moderator
Staff member
Joined
Apr 23, 2011
Messages
1,068
Location
Norway
Programming Experience
10+
Dot notation accesses/calls a member of the type or instance of type. Here 'x' is an instance of a type, and that type defines an Equals method, so the 'x' object can call it.

Equals method is actually defined in type object that is the base type for all types, inherited types can override this method for more specialized comparison.
 

Tomuks69

New member
Joined
Feb 22, 2021
Messages
2
Programming Experience
1-3
Let say I have a class with a property x=1. When this class is created it also inherits from object base class. This base class contains ToString() method. Why does this ToString() method takes these two properties via dots like x.ToString() not like ToString(x);

like how does it not to take that property into ToString() method
 

Skydiver

Staff member
Joined
Apr 6, 2019
Messages
2,583
Location
Chesapeake, VA
Programming Experience
10+
Actually, the base ToString() knows nothing about x property.
 
Top Bottom