is & as operators
Në shqip: Operatorët is dhe as
ShpjegimiSQ
is kontrollon nëse një objekt është i një tipi (dhe mund ta nxjerrë në variabël: if (k is Qen q)). as provon ta konvertojë dhe jep null nëse s'mundet, në vend që të hedhë gabim.
EnglishEN
is checks whether an object is of a type (and can pull it into a variable: if (a is Dog d)). as tries to convert and gives null if it can't, instead of throwing an error.
Si ta mendosh
Si roja që të kontrollon biletën te dera.
Lexoje në anglisht
Like a steward checking your ticket at the door.
Shembull kodicsharp
object o = "Arta";
if (o is string s) Console.WriteLine(s.Length);
var lista = o as List<int>; // null, pa gabim