What is Type safe in C#?

CsharpProgrammingServer Side Programming

Type safe in C# wouldn’t allow an object to sneak into other object’s memory. Let us see an example to understand the concept of −


public class One {
   public int Prop{ get; set;}

public class Two {
   public int Prop{get;set;}
   public int Prop1{get;set;}

Let’s say I have an object Class One −

One ob = new One();

Now you won’t be able to cast your object ob to the second class i.e. class Two. If you will cast it then a compile time error will arise because of the Type Safe feature in C#.

Updated on 21-Jun-2020 12:13:47