What is CTS in .NET Core?

πŸ’‘ Concept Name

CTS (Common Type System)

πŸ“˜ Quick Intro

CTS defines how types are declared, used, and managed in the .NET runtime. It ensures that objects written in different .NET languages can interact with each other using a unified type system.

🧠 Analogy / Short Story

Imagine people from different countries coming together. They all speak different languages but use the same currency β€” dollars. CTS is that currency. Even if VB.NET says β€œInteger” and C# says β€œint”, under the hood they both agree on the same structure, making cross-language transactions seamless.

πŸ”§ Technical Explanation

  • CTS is part of the .NET Standard and enforced by the CLR.
  • It standardizes data types like integers, floats, strings, etc., across all .NET languages.
  • CTS types are divided into:
    • Value Types (int, bool, structs)
    • Reference Types (classes, interfaces, arrays)
  • CTS allows language interoperabilityβ€”code written in C# can interact with VB.NET, F#, etc.

🎯 Purpose & Use Case

  • βœ… Enable cross-language integration
  • βœ… Ensure type safety across compiled assemblies
  • βœ… Define consistent rules for data types
  • βœ… Enhance runtime interoperability

πŸ’» Real Code Example

// C# Code
int number = 100; // CTS: System.Int32

// VB.NET Equivalent
' Dim number As Integer = 100  ' Also CTS: System.Int32

❓ Interview Q&A

Q1: What is CTS in .NET?
A: Common Type System defines how types are represented and ensures consistency across all .NET languages.

Q2: Why is CTS important?
A: It allows interoperability across languages like C#, VB.NET, F#, etc.

Q3: What are the two main categories of CTS types?
A: Value types and Reference types.

Q4: Is string a value or reference type in CTS?
A: Reference type.

Q5: How does CTS relate to CLR?
A: CTS is enforced by the CLR at runtime.

Q6: Is System.Int32 same across C# and VB.NET?
A: Yes, both compile to System.Int32 in CTS.

Q7: Can custom types follow CTS rules?
A: Yes, all .NET types follow CTS rules.

Q8: Does CTS impact type casting?
A: Yes, it defines rules for valid conversions and type safety.

Q9: What happens if CTS is violated?
A: Compilation or runtime type mismatch errors may occur.

Q10: Difference between CTS and CLS?
A: CTS defines all types; CLS is a subset that defines rules for language interoperability.

πŸ“ MCQs

Q1. What does CTS stand for in .NET?

  • Common Thread System
  • Common Type System
  • Code Translation Structure
  • Control Type Safety

Q2. Which category does 'int' fall under in CTS?

  • Reference Type
  • Class Type
  • Value Type
  • Primitive Object

Q3. Which of these is a reference type?

  • int
  • bool
  • string
  • char

Q4. Why is CTS important?

  • It compiles MSIL
  • It runs background services
  • It enables cross-language integration
  • It manages memory

Q5. What is the CTS type of C# int?

  • System.Int
  • System.Integer
  • System.Int32
  • System.Numeric

Q6. Can VB.NET and C# share the same CTS types?

  • No
  • Yes
  • Only for classes
  • Only for structs

Q7. Which runtime enforces CTS?

  • JIT
  • ILASM
  • CLR
  • .NET Compiler

Q8. Which of these is NOT a CTS value type?

  • int
  • bool
  • char
  • Array

Q9. Which CTS type category includes 'class'?

  • Value Type
  • Pointer Type
  • Reference Type
  • Method Type

Q10. What defines a safe cast between types in .NET?

  • C# Syntax
  • Runtime config
  • CTS rules
  • CLS guidelines

πŸ’‘ Bonus Insight

CTS, combined with CLS, makes .NET a powerful platform for building multilingual applications that compile to a unified runtime. It’s one of the key pillars that makes .NET language-agnostic.

πŸ“„ PDF Download

Need a handy summary for your notes? Download this topic as a PDF!

➑️ Next:

πŸ’¬ Feedback
πŸš€ Start Learning
Share:

Tags: