public class Person { public string Name; // Public field } Person p = new Person(); p.Name = "John"; Console.WriteLine(p.Name); // Output: John
public class Rectangle { private readonly int width; private readonly int height; public Rectangle(int w, int h) { width = w; height = h; } public int Area { get { return width * height; } } } Rectangle r = new Rectangle(5, 10); Console.WriteLine(r.Area); // Output: 50
internal class Employee { internal int Id; internal string Name; } Employee e = new Employee(); e.Id = 1; e.Name = "John"; Console.WriteLine(e.Name); // Output: JohnIn this example, we create an internal class called "Employee" and internal fields called "Id" and "Name". These fields can be accessed and modified only within the assembly they are defined in. Library used: Standard C# Library