Câu hỏi phỏng vấn C#
Câu hỏi

What you understand by Value types and Reference types in .NET? Provide some comparison

Câu trả lời

In .NET, there are two main categories of data types: value types and reference types. Here's an explanation of each and a comparison between them:

Value Types

Value types are data types that directly contain their values. When you declare a variable of a value type, the variable itself stores the actual value of the data. Some examples of value types in C# include:

  • Integers (int, short, long, byte)
  • Floating-point numbers (float, double, decimal)
  • Boolean (bool)
  • Characters (char)
  • Enumerations (enum)
  • Structures (struct)

When you assign a value type to a variable or pass it as an argument to a method, a copy of the value is created. Modifying the value in one variable does not affect the value in another variable.

Reference Types

Reference types are data types that store a reference to the actual data. When you declare a variable of a reference type, the variable itself stores a reference to the object's location in memory. Some examples of reference types in C# include:

  • Classes (class)
  • Interfaces (interface)
  • Arrays
  • Delegates
  • Strings

When you assign a reference type to a variable or pass it as an argument to a method, a copy of the reference is created. Both ...

junior

junior

Gợi ý câu hỏi phỏng vấn

senior

What is the difference between Func<string,string> and delegate ?

senior

Why to use lock statement in C#?

expert

in C#, when should we use abstract classes instead of interfaces with extension methods?

Bình luận

Chưa có bình luận nào

Chưa có bình luận nào