class property access only in parent only

  • Thread starter Thread starter essamce
  • Start date Start date
E

essamce

Guest
hi, i'm new to c#, i want to know a way to do so:

public class Location
{
public int X { get; set; }
public int Y { get; set; }

public Location() : this(0, 0) { }
public Location(int x, int y)
{
X = x;
Y = y;
}
}

public class Car
{
public Location CurrentLocation { get; set; }

void SomeCarMethod()
{
CurrentLocation.X = 5; // necessary

CurrentLocation = new Location(1, 2);
}
}

public class TempClass
{
public Car MyCar { get; set; }

void TempMethod()
{
MyCar.CurrentLocation.X = 6; // NOT ALLOWED way

var t = MyCar.CurrentLocation.X; // necessary

}
}


i'm using wpfCore3.1 vs2019

Continue reading...
 

Similar threads

K
Replies
0
Views
705
Krassimir Manev
K
K
Replies
0
Views
312
Krassimir Manev
K
D
Replies
0
Views
120
Decompressor
D
Back
Top