February 06, 2014 Re: Smart pointers instead of GC? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Namespace | On Wednesday, 5 February 2014 at 00:16:19 UTC, Namespace wrote: > On Wednesday, 5 February 2014 at 00:12:11 UTC, Shammah Chancellor wrote: >> On 2014-02-02 17:30:27 +0000, Namespace said: >> >>> Sounds good. But why @nullable instead of C# choice of "Type?" ? >> >> @nullable is not supposed to do the same thing as "Type?" (or rather the syntatic sugar for Nullabe<Type> template). Nullable<type> is to enable Value types to be null. For example: Nullable<Double> >> >> @nullable in D is supposed to allow reference types to contain null. In C# reference types are ALWAYS allowed to be null. >> >> -S > > class Foo { } > > Foo? f; > > It's the same. No it's not. In C#, Foo f can always be null. Foo? doesn't mean anything. http://msdn.microsoft.com/en-us/library/system.nullable(v=vs.110).aspx "A type is said to be nullable if it can be assigned a value or can be assigned null, which means the type has no value whatsoever. By default, all reference types, such as String, are nullable, but all value types, such as Int32, are not. In C# and Visual Basic, you mark a value type as nullable by using the ? notation after the value type. For example, int? in C# or Integer? in Visual Basic declares an integer value type that can be assigned null. The Nullable class provides complementary support for the Nullable<T> structure. The Nullable class supports obtaining the underlying type of a nullable type, and comparison and equality operations on pairs of nullable types whose underlying value type does not support generic comparison and equality operations." |
Copyright © 1999-2021 by the D Language Foundation