Share c# question mark after type

duynhuong380

New member
#csharp #questionmark #type #Varable #Programming

** C# đánh dấu câu hỏi sau loại **

Dấu câu hỏi (?) Sau một loại trong C# được sử dụng để chỉ ra rằng biến có thể thuộc bất kỳ loại nào.Điều này rất hữu ích khi bạn không biết loại dữ liệu nào sẽ được gán cho biến hoặc khi bạn muốn cho phép biến được gán cho một loại khác sau này.

Ví dụ: mã sau tuyên bố một biến có tên là `myvar` có thể thuộc bất kỳ loại nào:

`` `C#
int myvar = 10;
myvar = "Hello World";
`` `

Trong dòng đầu tiên, biến `myvar` được khai báo là một số nguyên.Trong dòng thứ hai, biến được gán giá trị của 10. Trong dòng thứ ba, biến được gán giá trị của chuỗi "Hello World".

Dấu câu hỏi sau loại cho phép biến được gán cho bất kỳ loại dữ liệu nào.Điều này rất hữu ích khi bạn không biết loại dữ liệu nào sẽ được gán cho biến hoặc khi bạn muốn cho phép biến được gán cho một loại khác sau này.

**Người giới thiệu**

* [C# Hướng dẫn: Biến] (C# - Variables)
* [C# Tham khảo: Biến] (Declaration statements - local variables and constants, var, local reference variables (ref locals) - C#)

** hashtags **

* #csharp
* #biến
* #Programming
* #Kiểu
* #dấu chấm hỏi
=======================================
#csharp #questionmark #type #variable #Programming

**C# Question Mark after Type**

The question mark (?) after a type in C# is used to indicate that the variable can be of any type. This is useful when you don't know what type of data will be assigned to the variable, or when you want to allow the variable to be assigned to a different type later on.

For example, the following code declares a variable called `myVar` that can be of any type:

```c#
int myVar = 10;
myVar = "Hello world";
```

In the first line, the variable `myVar` is declared as an integer. In the second line, the variable is assigned the value of 10. In the third line, the variable is assigned the value of the string "Hello world".

The question mark after the type allows the variable to be assigned to any type of data. This is useful when you don't know what type of data will be assigned to the variable, or when you want to allow the variable to be assigned to a different type later on.

**References**

* [C# Tutorial: Variables](https://www.tutorialspoint.com/csharp/csharp_variables.htm)
* [C# Reference: Variables](https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/var)

**Hashtags**

* #csharp
* #variables
* #Programming
* #type
* #questionmark
 
Join Telegram ToolsKiemTrieuDoGroup
Back
Top