# Show object properties

{% hint style="info" %}
You can use `dotnet watch` and observe the result of code changes instantly on the browser!
{% endhint %}

### Display properties of an object

{% hint style="info" %}
It is not recommended to declare classes in view code, they need to be declared in their respective `Models` directory or in page specific `PageModel`
{% endhint %}

```cshtml
@page

@{
    var joe = new Person()
    {
        Name = "Sam",
        Age = 25
    };
}
   
<p>Name: @joe.Name</p>
<p>Age: @joe.Age</p>

@functions{
    public class Person
    {        
        public string Name { get; set; }
        public int Age { get; set; }
    }
}
```

### Display properties of a collection of objects

```cshtml
@page

@{
    var people = new List<Person>(){
        new Person()
        {
            Name = "Sam",
            Age = 25
        },
        new Person()
        {
            Name = "Ted",
            Age = 30
        }
    };
}
   
@foreach (var item in people)
{
    <p>Name: @item.Name</p>
    <p>Age: @item.Age</p>
}

@functions{
    public class Person
    {        
        public string Name { get; set; }
        public int Age { get; set; }
    }
}
```
