C Sharp (C#) - Properties and Encapsulation
What will be the output of the following C# code?
class User {
private string _name = "Alice";
public string Name { get { return _name; } }
}
var user = new User();
Console.WriteLine(user.Name);What will be the output of the following C# code?
class User {
private string _name = "Alice";
public string Name { get { return _name; } }
}
var user = new User();
Console.WriteLine(user.Name);Name property is read-only with a get accessor returning "Alice".user.Name returns "Alice", so it prints "Alice".15+ quiz questions · All difficulty levels · Free
Free Signup - Practice All Questions