本文介绍了创建一个空对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在c#中创建一个空对象及其用途?

how to Creating a Null Object in c# and what it use???

推荐答案

SomeObject so = new SomeObject();
so.DoSomething();
so.Dispose();
so = null; // We are now absolutely sure the SomeObject so was referencing to is no longer referenced by so.
// This should theoretically not be necessary in .NET.


创建一个可空对象:
可以创建可空类型 [ ^ ]的值类型,否则将不允许使用null引用.


Create a Nullable Object:
It is possible to create Nullable types[^] of value types that would otherwise not allow a null reference.

Nullable<int> i1 = null; // Actually has a null reference.
int? i2 = null; // Same as code above.


这篇关于创建一个空对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-03 22:34
查看更多