Ur Mom Ur Mom - 18 days ago 5
C# Question

Strange line in C# camera code

My team is working on documentation for a robot project. We're currently documenting some camera code but we don't understand some lines.

public Mat Image { get; set; }
public double GyroAngle { get; set; }


Could anyone explain what these lines are doing? If the
GyroAngle
is simply a
double
why does it have
{ get; set; }
? Thanks in advance.

Answer

The MSDN has some useful info.

public string FirstName { get; set; } = "Jane";

The class that is shown in the previous example is mutable. Client code can change the values in objects after they are created. In complex classes that contain significant behavior (methods) as well as data, it is often necessary to have public properties. However, for small classes or structs that just encapsulate a set of values (data) and have little or no behaviors, you should either make the objects immutable by declaring the set accessor as private (immutable to consumers) or by declaring only a get accessor (immutable everywhere except the constructor). For more information, see How to: Implement a Lightweight Class with Auto-Implemented Properties.