Variables in .NET are either reference types or value types. Value typ translation - Variables in .NET are either reference types or value types. Value typ Vietnamese how to say

Variables in .NET are either refere

Variables in .NET are either reference types or value types. Value types are primitives such as integers and booleans or structures (and can be identified because they inherit from System.ValueType). Boolean variables, when declared, have a default value:

bool mybool;
//mybool == false
Reference types, when declared, do not have a default value:

class ExampleClass
{
}

ExampleClass exampleClass; //== null
If you try to access a member of a class instance using a null reference then you get a System.NullReferenceException. Which is the same as Object reference not set to an instance of an object.

The following code is a simple way of reproducing this:

static void Main(string[] args)
{
var exampleClass = new ExampleClass();
var returnedClass = exampleClass.ExampleMethod();
returnedClass.AnotherExampleMethod(); //NullReferenceException here.
}

class ExampleClass
{
public ReturnedClass ExampleMethod()
{
return null;
}
}

class ReturnedClass
{
public void AnotherExampleMethod()
{
}
}
This is a very common error and can occur because of all kinds of reasons. The root cause really depends on the specific scenario that you've encountered.

If you are using an API or invoking methods that may return null then it's important to handle this gracefully. The main method above can be modified in such a way that the NullReferenceException should never be seen by a user:

static void Main(string[] args)
{
var exampleClass = new ExampleClass();
var returnedClass = exampleClass.ExampleMethod();

if (returnedClass == null)
{
//throw a meaningful exception or give some useful feedback to the user!
return;
}

returnedClass.AnotherExampleMethod();
}
All of the above really just hints at .NET Type Fundamentals, for further information I'd recommend either picking up CLR via C# or reading this MSDN article by the same author - Jeffrey Richter. Also check out this, much more complex, example of when you can encounter a NullReferenceException.

Some teams using Resharper make of JetBrains attributes to annotate code to highlight where nulls are (not) expected.
0/5000
From: -
To: -
Results (Vietnamese) 1: [Copy]
Copied!
Biến ở .NET là tài liệu tham khảo loại hoặc giá trị loại. Giá trị loại là nguyên thủy như số nguyên và phép toán luận hoặc cấu trúc (và có thể được xác định bởi vì họ thừa hưởng từ System.ValueType). Boolean biến, khi bùng nổ, có một giá trị mặc định:bool mybool;mybool == falseTham khảo các loại, khi tranh bùng nổ, không có một giá trị mặc định:lớp ExampleClass{}ExampleClass exampleClass; == nullNếu bạn cố gắng truy cập một thành viên của một trường hợp lớp bằng cách sử dụng một tài liệu tham khảo không sau đó bạn nhận được một System.NullReferenceException. Đó là giống như đối tượng tham chiếu không được đặt để một thể hiện của một đối tượng.Mã sau đây là một cách đơn giản để tái tạo điều này:tĩnh void Main (string [] args){ var exampleClass = mới ExampleClass(); var returnedClass = exampleClass.ExampleMethod(); returnedClass.AnotherExampleMethod(); NullReferenceException ở đây.}lớp ExampleClass{ khu vực ReturnedClass ExampleMethod() { trở về null; }}lớp ReturnedClass{ khu vực vô hiệu AnotherExampleMethod() { }}Đây là một lỗi rất phổ biến và có thể xảy ra vì tất cả các loại lý do. Nguyên nhân gốc rễ thực sự phụ thuộc vào trường hợp cụ thể mà bạn đã gặp phải.Nếu bạn đang sử dụng một API hoặc gọi phương pháp có thể trở lại bằng không sau đó nó là quan trọng để xử lý này gracefully. Phương pháp chính ở trên có thể được thay đổi theo cách NullReferenceException không bao giờ nên được xem bởi một người sử dụng:tĩnh void Main (string [] args){ var exampleClass = mới ExampleClass(); var returnedClass = exampleClass.ExampleMethod(); Nếu (returnedClass == null) { ném một ngoại lệ có ý nghĩa hoặc cung cấp cho một số thông tin phản hồi hữu ích cho người dùng! trở lại; } returnedClass.AnotherExampleMethod();}Tất cả các gợi ý thực sự chỉ ở trên tại .NET loại nguyên tắc cơ bản, cho biết thêm thông tin tôi muốn giới thiệu hoặc chọn lên CLR qua C# hoặc đọc này bài viết MSDN của cùng tác giả - Jeffrey Richter. Ngoài ra kiểm tra này, ví dụ phức tạp hơn, trong khi bạn có thể gặp phải một NullReferenceException.Một số đội bằng cách sử dụng Resharper làm cho JetBrains thuộc tính chú thích mã để làm nổi bật nơi nulls (không) được dự kiến.
Being translated, please wait..
Results (Vietnamese) 2:[Copy]
Copied!
Các biến trong .NET là kiểu tham chiếu hoặc các loại giá trị. Giá trị các loại nguyên thủy như là số nguyên và các phép toán hay các cấu trúc (và có thể được xác định bởi vì họ thừa hưởng từ System.ValueType). Biến Boolean, khi tuyên bố, có một giá trị mặc ​​định: bool mybool; // mybool == false loại tham khảo, khi tuyên bố, không có một giá trị mặc ​​định: lớp ExampleClass {} ExampleClass exampleClass; // == Null Nếu bạn cố gắng truy cập vào một thành viên của một trường lớp bằng cách sử dụng một tham chiếu null sau đó bạn sẽ có được một System.NullReferenceException. . Mà là giống như đối tượng tham chiếu không được đặt để một thể hiện của một đối tượng Các mã sau đây là một cách đơn giản để tái tạo này: static void Main (string [] args) {var exampleClass = ExampleClass mới (); var returnedClass = exampleClass. ExampleMethod (); returnedClass.AnotherExampleMethod (); // NullReferenceException đây.} Class ExampleClass {công ReturnedClass ExampleMethod () {trở lại null;}} class ReturnedClass {public void AnotherExampleMethod () {}} Đây là một lỗi rất phổ biến và có thể xảy ra vì tất cả các loại lý do. Nguyên nhân gốc rễ thật sự phụ thuộc vào kịch bản cụ thể mà bạn đã gặp phải. Nếu bạn đang sử dụng một API hoặc cách gọi phương pháp đó có thể trở lại null thì điều quan trọng là để xử lý này một cách duyên dáng. Phương pháp chủ yếu trên có thể được biến đổi theo một cách mà các NullReferenceException không bao giờ được nhìn thấy bởi một người dùng: static void Main (string [] args) {var exampleClass = ExampleClass mới (); var returnedClass = exampleClass.ExampleMethod (); nếu (returnedClass == null) {// ném một ngoại lệ có ý nghĩa hoặc đưa ra một số thông tin phản hồi hữu ích cho người sử dụng! return;} returnedClass.AnotherExampleMethod ();} Tất cả những điều trên thực sự chỉ là gợi ý NET Loại cơ bản, để biết thêm thông tin tôi d nên hoặc nhặt CLR thông qua C # hoặc đọc MSDN bài viết này bởi cùng một tác giả - Jeffrey Richter. Ngoài ra kiểm tra này, phức tạp hơn nhiều, ví dụ khi bạn có thể gặp phải một NullReferenceException. Một số nhóm sử dụng Resharper làm của JetBrains thuộc tính chú thích mã để làm nổi bật nơi null được (không) mong đợi.






















































Being translated, please wait..
 
Other languages
The translation tool support: Afrikaans, Albanian, Amharic, Arabic, Armenian, Azerbaijani, Basque, Belarusian, Bengali, Bosnian, Bulgarian, Catalan, Cebuano, Chichewa, Chinese, Chinese Traditional, Corsican, Croatian, Czech, Danish, Detect language, Dutch, English, Esperanto, Estonian, Filipino, Finnish, French, Frisian, Galician, Georgian, German, Greek, Gujarati, Haitian Creole, Hausa, Hawaiian, Hebrew, Hindi, Hmong, Hungarian, Icelandic, Igbo, Indonesian, Irish, Italian, Japanese, Javanese, Kannada, Kazakh, Khmer, Kinyarwanda, Klingon, Korean, Kurdish (Kurmanji), Kyrgyz, Lao, Latin, Latvian, Lithuanian, Luxembourgish, Macedonian, Malagasy, Malay, Malayalam, Maltese, Maori, Marathi, Mongolian, Myanmar (Burmese), Nepali, Norwegian, Odia (Oriya), Pashto, Persian, Polish, Portuguese, Punjabi, Romanian, Russian, Samoan, Scots Gaelic, Serbian, Sesotho, Shona, Sindhi, Sinhala, Slovak, Slovenian, Somali, Spanish, Sundanese, Swahili, Swedish, Tajik, Tamil, Tatar, Telugu, Thai, Turkish, Turkmen, Ukrainian, Urdu, Uyghur, Uzbek, Vietnamese, Welsh, Xhosa, Yiddish, Yoruba, Zulu, Language translation.

Copyright ©2025 I Love Translation. All reserved.

E-mail: