Home  >  Article  >  Backend Development  >  What is type safety in C#?

What is type safety in C#?

PHPz
PHPzforward
2023-09-17 22:57:03799browse

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.

Example

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!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete