Syntax

C# Define a Class Syntax

In C#, define a class: defines a class with a property — public class Dog { public string Name { get; set; } = ""; }

Quick Answer

Syntax
public class Dog { public string Name { get; set; } = ""; }
C#Syntax

Define a Class

Code example
public class Dog { public string Name { get; set; } = ""; }

Defines a class with a property.

Learn More

How to define a class in C#

  1. Open your C# file or editor.
  2. Copy the example, then replace its sample names and values for your code.

C# Define a Class Syntax

Use public class Dog { public string Name { get; set; } = ""; }.

Related Syntax References

Frequently asked questions

What is the C# syntax for define a class?

Use this pattern: public class Dog { public string Name { get; set; } = ""; }

Can I copy this C# code example?

Yes. Use Copy code and adapt the example to your program.

Is this C# syntax different on Mac or Windows?

No. The language syntax is the same across operating systems.

Official source · How we verify