CodShot
C# Public

Simple Class with Property

Create a small class with properties and instantiate it.

#csharp #class #oop #beginner
C#
using System;

Product product = new()
{
    Name = "Keyboard",
    Price = 49.99m
};

Console.WriteLine($"{product.Name}: {product.Price:C}");

class Product
{
    public string Name { get; set; } = "";
    public decimal Price { get; set; }
}

Notes

Auto-properties are the cleanest syntax for simple data objects.

Snippet actions

CodShot user
CodShot user
Updated: 2026-06-08 14:33
Public snippets
0
Forks
CodShot AI Help
Ask about CodShot features, plans, workspace, AI limits, referrals, and public help topics.
Hi! I can help you understand how CodShot works. What would you like to know?
For account-specific or sensitive issues, please open a support ticket. Open support