C# vs C++ - tipuri nulabile
int? notaExamen = null; // studentul nu a dat inca examenul
if (notaExamen.HasValue)
Console.WriteLine($"Nota: {notaExamen.Value}");
else
Console.WriteLine("Examenul nu a fost sustinut.");
// Operatorul ?? (null-coalescing) - ofera o valoare implicita
int notaFinala = notaExamen ?? 0; // daca e null , foloseste 0
Console.WriteLine($"Nota finala: {notaFinala}");
// Operatorul ?. (null-conditional) - acces sigur la membri
string text = null;
int? lungime = text?.Length; // nu arunca exceptie, returneaza null
Console.WriteLine(lungime ?? -1); // afiseaza -1Last updated