Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> C#

Type Safe ใน C# คืออะไร

Type Safe ใน C# ป้องกันไม่ให้ออบเจกต์เข้าถึงหน่วยความจำของออบเจกต์อื่นได้ ตัวอย่าง:

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

สร้างออบเจกต์ Class One:

One ob = new One();

ไม่สามารถ Cast ob เป็น Class Two ได้ จะเกิด Compile-time Error เพราะ Type Safe ของ C#