int
, double
, bool
, char
, struct
string
, class
, object
, array
, interface
int?
, bool?
(helpful when working with databases).+
, , , /
, %
), Logical (&&
, ||
, !
), Comparison (==
, !=
, <
, >
).if/else
, switch
, for
, foreach
, while
, do while
, break
, continue
.Classes & Objects
Defined with class
.
Example:
public class Product {
public int Id { get; set; }
public string Name { get; set; }
}
Constructors
Properties
{ get; set; }
.Methods
Inheritance
One class derives from another using :
.
Example:
public class Animal { public void Eat() {} }
public class Dog : Animal { public void Bark() {} }
Polymorphism
Generics
List<T>
, Dictionary<TKey, TValue>
.Interfaces
Define a contract without implementation.
Example:
public interface IRepository<T> {
void Add(T entity);
T GetById(int id);
}
Abstract Classes