Easy csharp

OOP — Person class with properties #85

Problem

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

Hints
  • public string Name { get; set; }

Your solution

TestStatusDetails
Ready — edit the code above and click Run or Submit.

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.

Discussion

0

Sign in to join the discussion.

No discussions yet — ask the first question!

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