Tsallaka zuwa abun ciki
Justice Tech School

C# Enums, Structs and Records

An enum names a set of constants. A struct is a value type for small data. A record gives value based equality and a short syntax, ideal for data.

Example
enum Level { Beginner, Intermediate, Advanced }
record Person(string Name, int Age);
struct Pt { public int X, Y; }
var a = new Person("Ada", 21);
var b = new Person("Ada", 21);
Console.WriteLine(a == b);
Console.WriteLine(Level.Advanced + " " + (int)Level.Advanced);

Exercise

Short data type.

 Person(string Name);

Quiz Test

What is special about records?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.