I tend to avoid using switch/case for quite irrational reasons. The break statement just looks wrong and I can't layout the code in a way I find at all pleasing. I'll almost always use a sequence of else if conditions instead. In my ideal world, it'd look like... switch (x) { case 1: { /* ... */ } case 2: case 3: { /* ... */ } } And before anyone points it out, switch is the same as else if when the thing being compa…
What’s New in C# 7.0
171–180 of 278 posts
Re: What’s New in C# 7.0
#172Earlier quoted context omitted.
I find that the verbosity can be minimised by type aliasing. E.g: using Complex = System.Tuple ; Edit: Clarity
But then you might as well declare a class or structure to store the data. The point of tuples is to be self-contained.
using Complex = System.Tuple;
is less verbose than public class Complex
{
public double i { get; set; }
public double j { get; set; }
}Re: What’s New in C# 7.0
#173What's the point of GetCoordinates(out var x, out var y) over destructuring assignment like var x, var y = GetCoordinates(); the former looks completely backwards.
Re: What’s New in C# 7.0
#174What's the point of GetCoordinates(out var x, out var y) over destructuring assignment like var x, var y = GetCoordinates(); the former looks completely backwards.
This way you would get a Boolean if the coordinates exist and would not have to perform validation on the out variables.
Re: What’s New in C# 7.0
#175Having done a lot of python recently, this looks great (and familiar). But some things feel a little bit rushed: - In the example "(o is int i || (o is string s && int.TryParse(s, out i))": When reading this statement as a human, o is obviously not an int when it comes down to the TryParse function. But if the 1st part was removed, the 2nd part wouldn't be valid either. I know this is technically how declarations wor…
The page said for type patterns it will "test that the input has type T, and if so, extracts the value of the input into a fresh variable x of type T", so if o is an int it'll be extracted to a fresh int i with that value
But the out syntax in TryParse isn't the new one they mentioned, it's the current one that requires predeclared variables - to be new it'd be out int i or out var i. So i is already declared as an int before this code example? In that case how can the first bit work? Does it not create a "fresh variable" if there's already one in scope with the desired name and type? That could be quite confusing, usual behavior is to compile error if an inner scoped variable conflicts with an outer one, I'm not sure I understand why this should be different.
Re: What’s New in C# 7.0
#176Re: What’s New in C# 7.0
#177I tend to avoid using switch/case for quite irrational reasons. The break statement just looks wrong and I can't layout the code in a way I find at all pleasing. I'll almost always use a sequence of else if conditions instead. In my ideal world, it'd look like... switch (x) { case 1: { /* ... */ } case 2: case 3: { /* ... */ } } And before anyone points it out, switch is the same as else if when the thing being compa…
switch (x)
{
case 1:
{
/* ... */
}
break;
case 2:
case 3:
{
/* ... */
}
break;
}Re: What’s New in C# 7.0
#178CSharp once again showing it is the best language in terms of features and improvements. Great job all round by the designers.
Nonetheless C# is a nice language. I enjoy writing C# code, just as I enjoy writing Swift code.
Re: What’s New in C# 7.0
#179Earlier quoted context omitted.
So true. Between 1998 and 2000 VB6 was perfect, you could develop Windows GUI applications in a rapid manner. The VB6 IDE, the Windows UI guideline, the VB6 API, everything was great. And PlanetSourceCode.com was what was later SourceForge and nowadays GitHub. When I read about Microsoft's vision for .Net in 1999 about applications running as a service over the internet (that was their original idea), I thought that…
> Between 1998 and 2000 VB6 was perfect, you could develop Windows GUI applications in a rapid manner Delphi was much better.
Re: What’s New in C# 7.0
#180CSharp once again showing it is the best language in terms of features and improvements. Great job all round by the designers.
I'd say Swift is more or less in line with C# with regards to functionality. Many new features added to C# seem to already exist in Swift. Swift could use some async/await mechanism en sometimes it's a bit annoying to typecast simple types for calculations, but otherwise Swift is a really sweet language to work with. Nonetheless C# is a nice language. I enjoy writing C# code, just as I enjoy writing Swift code.