Object-Oriented Programming in .NET
Object-oriented programming (OOP) is a programming paradigm that revolves around the concept of objects, which are instances of classes. In .NET, OOP is a fundamental concept that allows developers to organize their code into reusable and modular components.
Classes and Objects
In OOP, a class is a blueprint for creating objects. It defines the properties and behaviors that an object of that class will have. The properties are represented by fields and the behaviors are represented by methods.
Here's an example of a class representing a person:
TEXT/X-CSHARP
1public class Person
2{
3 public string Name { get; set; }
4 public int Age { get; set; }
5
6 public void SayHello()
7 {
8 Console.WriteLine("Hello, my name is " + Name);
9 }
10}
xxxxxxxxxx
using System;
OUTPUT
:001 > Cmd/Ctrl-Enter to run, Cmd/Ctrl-/ to comment