c# - Why does Nullable<T> HasValue property not throw NullReferenceException on Nulls? -


निम्नलिखित कोड पर विचार करें:

  दिनांकटाइम? Ndate = null; Console.WriteLine (ndate.HasValue);  

मुझे उम्मीद है कि एक NullReferenceException, लेकिन HasValue वास्तव में झूठी वापसी करेंगे। हालांकि, चूंकि ndate शून्य है, संपत्ति का आह्वान कैसे सफल होता है, क्योंकि संपत्ति के दावे को लागू करने के लिए कोई वस्तु नहीं है? तकनीकी रूप से, "ndate" शून्य नहीं है - यह मूल्य का प्रकार है, इसके मूल्य के रूप में निर्दिष्ट किया गया है।

शून्य।

जब आप दिनांकटाइम लिखते हैं, तो यह सिर्फ लघुकथा है, जो एक स्ट्रेट है इसका कोई रास्ता नहीं है तकनीकी रूप से शून्य हो, क्योंकि यह कोई संदर्भ प्रकार नहीं है।


Comments

Popular posts from this blog

c++ - QtQuick: QQmlApplicationEngine failed to load component qrc:/main.qml:23 Invalid attached object assignment -

sql - dynamically varied number of conditions in the 'where' statement using LINQ -

asp.net - getting a value of selected radiobutton in LoadViewState -