non-nullable

Whats wrong with non nullable objects?

I have been looking at DbC lately and Spec# which seem to have support for non nullable objects. Unfortunately Spec# seem to have been abandoned. Spec# seemed to have lots of nice language features built in so why was it abandoned? Would there be any problem with letting all objects be non-nullable by default so you would have to write...

How can I run a query on a dataset that returns different columns to the table?

Hi again all, I'm trying to pull some data from a SQL table in my dataset using C#. In this case I do not need all the columns just a few specific ones, however as I am not pulling back a column with a mandatory NOT NULL, the copy of the table is throwing the exception "Failed to enable constraints. One or more rows contain values...

Making a Non-nullable value type nullable

I have a simple struct that has limited use. The struct is created in a method that calls the data from the database. If there is no data returned from the database I want to be able to return a null, but Visual Studio complains, Cannot convert null to PackageName.StructName because it is a non-nullable value type. How can I make it nul...

About the non-nullable types debate

I keep hearing people talk about how non-nullable reference types would solve so many bugs and make programming so much easier. Even the creator of null calls it his billion dollar mistake, and Spec# has introduced non-nullable types to combat this problem. EDIT: Ignore my comment about Spec#. I misunderstood how it works. EDIT 2: I m...

Why is null not allowed for DateTime in C#?

Why it is not allowed to assign null to a DateTime in C#? How has this been implemented? And can this feature be used to make your own classes non-nullable? Example: string stringTest = null; // Okay DateTime dateTimeTest = null; // Compile error I know that I can use DateTime? in C# 2.0 to allow null to be assigned to dateTimeTest a...

Non-nullable reference types

I'm designing a language, and I'm wondering if it's reasonable to make reference types non-nullable by default, and use "?" for nullable value and reference types. Are there any problems with this? What would you do about this: class Foo { Bar? b; Bar b2; Foo() { b.DoSomething(); //valid, but will cause exception ...

Alternatives to nullable types in C#

I am writing algorithms that work on series of numeric data, where sometimes, a value in the series needs to be null. However, because this application is performance critical, I have avoided the use of nullable types. I have perf tested the algorithms to specifically compare the performance of using nullable types vs non-nullable type...

How to make computed column not nullable?

So far I've been using ISNULL(dbo.fn_GetPrice(ItemId), 0) to make it not nullable (rather call it default-valued, but whatever). Is this the right way? ...

How can I get close to non-nullable types in C# today?

I've read many of the non-nullable questions and answers. It looks like the best way to get close to non-nullable types in C# (4.0) is Jon Skeet's NonNullable<> hack. However, it seems that C++/CLI has solved much of the problem by supporting managed references: Foo% (instead of native C++ Foo&). The compiler makes this work by adding...

Value of unassigned non-nullable variable (C#)

Just curious. If you go: string myString; Its value is null. But if you go: int myInt; What is the value of this variable in C#? Thanks David ...

What would we do without NULL?

I once read that having nullable types is an absolute evil. I believe it was in an article written by the very person who created them(in Ada?) I believe this is the article Anyway, so what if by default a language like C# used non-nullable types? How would you replace some of the common idioms in C# or Ruby or any other common language...