Also, C# 9.0 is really cool. Will be abusing the new pattern matching stuff once we get a chance to upgrade. Looking like 3.1=>5.0 is going to be a non-event for us based on the current migration guides.
Also, C# 9.0 is really cool. Will be abusing the new pattern matching stuff once we get a chance to upgrade. Looking like 3.1=>5.0 is going to be a non-event for us based on the current migration guides.
The keyword is the declaration is `record`. So you would write your record:
record Person(string FirstName, string LastName);
Source: I am one of the language designers on C# :) public data class Person(string FirstName, string LastName);
It seems https://docs.microsoft.com/en-us/dotnet/csharp/whats-new/csh... is saying what you wrote above though.Seems my previous comment was based on outdated/wrong information, I'm sorry and thanks for clarifying :)
Edit: Seems the post I wrote was published 20th May (probably written before) and that was the same date someone said the same thing as my comment here in the discussion about the "records" feature https://github.com/dotnet/csharplang/issues/39#issuecomment-...
https://devblogs.microsoft.com/dotnet/announcing-net-5-0-rc-...
With is just building on the anti-pattern where .NET programmers are too lazy to implement constructors.
What? And aren't records just a lazy way to make classes then?
The correct path would have been to require primary constructors for records as the only point of entry for data, declare initializers incompatible with primary constructors, and then just synthesize a method for creating copies - but hey, then you might as well just use Scala.
That has always seemed like a strange omission, but I can't say it's really caused me distress :)
Personally, I'm looking forward to the `half` type, the extra GC diagnostic info, improved app trimming, improved ASN and certificate handling, and of course the improved performance and increased reach of Span. But I think most of all, I'm looking forward to a long term plan and no more .NET Standard/Core mismatch.
I wish they made C# support a notion of generic alrgebras.
After seeing other libraries do so, I've fallen into the habit of using a singleton 'Unit' or 'Empty' Type. (This technically also falls in line with the .NET conventions of DbNull.Value and Missing.Value)
Actually, typing that out, I wonder if we all should have been using Missing.Value all along? :)
Also, I don't see how you could say DBNull is responsible for forcing object on us. They could have just as easily made it a struct and i dont see what it would solve.
Fortunately, it's super easy to tell the difference. `DatabaseQuery()` vs `SomeOtherFunction()`. See?
> Also, I don't see how you could say DBNull is responsible for forcing object on us. They could have just as easily made it a struct and i dont see what it would solve.
Doesn't matter. Even if it was a struct, the only way to store both kinds of value in one variable is to declare it an `object`, even if it was a struct. `null` is a perfectly legal value for a `string` variable, but as soon as the possibility for some other null object (or struct) is raised, the target variable must be `object`. C# doesn't do unions (as a first class language feature anyway).
https://docs.microsoft.com/en-us/dotnet/csharp/language-refe...
I seem to be having some trouble explaining my point. Maybe this will illustrate better. What should be the declared return type of this method?
??? GetValue() {
if (condition) {
return 7;
}
else {
return DBNull.Value;
}
}int? someNumber = resultset.Records[0]["some_column"] as int?;
That code sample is exactly how I'd write it. My only problem is that DBNull ever existed in the first place.
I get that it was annoying, but most of .NET before 3.5 was anyway. It's just nobody bothered to make the right syntactic sugar.
Yes, I have a point of view.
There's really no reason why you have to touch DBNull at all.
var dt = new DataTable();
dt.Columns.Add("name", typeof(string));
//dt.Columns.Add("count", typeof(int?)); // NotSupportedException: DataSet does not support System.Nullable<>.
dt.Columns.Add("count", typeof(int));
var row=dt.NewRow();
row["name"] = null;
//row["count"] = null; // ArgumentException: Cannot set Column 'count' to be null. Please use DBNull instead.
row["count"] = DBNull.Value;
dt.Rows.Add(row);I also don't like that DBNull and Missing are reference types, it would be better to use a value type for this to avoid having to do null checks similar to Nullable<T> but I guess in this case it doesn't matter since they are used for different purposes.