Easy csharp

OOP — Person class with properties #31

Problem

Create a Person class with Name and Age; print both.

Hints
  • public string Name { get; set; }

Your practice code

Ready — edit the code above and click Run.

Solution

using System;

class Person { public string Name { get; set; } public int Age { get; set; } }
class Program {
    static void Main() {
        var p = new Person { Name = "Ali", Age = 25 };
        Console.WriteLine($"{p.Name} is {p.Age}");
    }
}

Try solving on your own first, then reveal the official answer.

Explanation

Auto-properties are standard C# OOP—encapsulation with get/set.

Toolliyo Assistant
Ask about tutorials, ebooks, training, pricing, mentor services, and support. I use public site content only—not admin or internal tools.

care@toolliyo.com

Need callback? Share your details