Home > Article > Backend Development > What is type safety in C#?
#In C#, type safety will not allow one object to sneak into the memory of another object. Let's see an example to understand this concept.
public class One { public int Prop{ get; set;} } public class Two { public int Prop{get;set;} public int Prop1{get;set;} }
Let us assume that I have an object Class One −
One ob = new One();
Now you will not be able to convert the object ob to the second class i.e. class Two. If you try to convert, a compile-time error will occur due to C#'s type safety features.
The above is the detailed content of What is type safety in C#?. For more information, please follow other related articles on the PHP Chinese website!