Live data from Hacker News

C# 9 top-level programs and target-typed expressions

developers.redhat.com

111–120 of 188 posts

Re: C# 9 top-level programs and target-typed expressions

#111

> Top-level programs allow you to write the main method of your application without having to add a class with a static Main method Riveting stuff happening in .Net land! Sarcasm aside, this seems like such a small, oddly-specific, once-off feature that its like...why bother? Any C# devs want to enlighten me here?

Why not bother?

This mindset is one of the core features of .NET-land - Microsoft just goes ahead and implements anything useful. It's why we have a gigantic standard library ("framework") filled with every function under the sun and some multiple times. We didn't have to wait until C++20 to get string.Contains. Sometimes the features Microsoft implements are more useful than others but most of them are a little useful to somebody.

Re: C# 9 top-level programs and target-typed expressions

#112
post #2

Unfortunately the new tricks can't be used when the codebase is still stuck on .net framework :(

Allegedly there's an upgrade path from .NET 4.8 to .NET 5.

Allegedly there's also a route to the top of Mt Everest.

For some of us the "upgrade path" is impassable.

Re: C# 9 top-level programs and target-typed expressions

#113
post #14

Earlier quoted context omitted.

Allegedly there's an upgrade path from .NET 4.8 to .NET 5.

The upgrade path is massive rewrites, something most business are wary of. For good reasons. MS really made a grave mistake by coupling the evolution of the C# language to the .NET version. This means all projects on the .NET framework is now also stuck with an obsolete language version for no good reason. It is becoming a a lot less fun to be a C# developer because you more often will have to work with obsolete tool…

>It is becoming a a lot less fun to be a C# developer because you more often will have to work with obsolete tools.

This

Re: C# 9 top-level programs and target-typed expressions

#114

Can I just create a single .cs file somewhere, and execute it by typing its name? No Visual Studio solution/project shenanigans? That’s my dream. Top-level programs to eliminate boilerplate is a nice related step.

Not quite at a single .cs file, but there is the third-party dotnet-script [1] installed as a global tool to run .csx files. That's been around longer that C# language support for top level statements.

[1] https://github.com/filipw/dotnet-script

Re: C# 9 top-level programs and target-typed expressions

#115
post #29
post #2

Unfortunately the new tricks can't be used when the codebase is still stuck on .net framework :(

There are many paths out of hell. Check out the windows compatibility pack for all things active directory, WCF & System.Drawing: https://docs.microsoft.com/en-us/dotnet/core/porting/windows... Winforms is probably a no-go on migration, but you should definitely check out Blazor if you want to develop any new business apps. We have constructed some incredibly complex business dashboards using this framework and cant…

> There are many paths out of hell.

Unless you are maintaining a Webforms project :(

Everything new is core or now .NET5, but I see no way to migrate our main website without essentially stopping all other development work for a long time.

Re: C# 9 top-level programs and target-typed expressions

#116
post #73

Earlier quoted context omitted.

Are you sure? My personal reluctance to C# has been that it's not handy for the stuff I do that needs to run on Windows, Mac, and Linux, which is everything.

Relative to what? Assembly?

C/C++. Java. Python. JavaScript.

Re: C# 9 top-level programs and target-typed expressions

#117
Can anyone comment on cross-platform GUI for .net? Last time I seriously investigated it, Gtk# seemed to be the primary option. Some quick googling found avalonia, but no clue if that's a reasonable GUI to use. I'm guessing MS isn't planning on porting WPF to linux (though I suppose linking with wine might work)...

Re: C# 9 top-level programs and target-typed expressions

#118

Can anyone comment on cross-platform GUI for .net? Last time I seriously investigated it, Gtk# seemed to be the primary option. Some quick googling found avalonia, but no clue if that's a reasonable GUI to use. I'm guessing MS isn't planning on porting WPF to linux (though I suppose linking with wine might work)...

It looks like MAUI [1] is the path forward

[1] https://devblogs.microsoft.com/dotnet/introducing-net-multi-...

Re: C# 9 top-level programs and target-typed expressions

#119
post #91

I mean, top-level programs are nice, I guess? IMO it's more of a means of attracting non-.NET developers into the fold. I work in a .NET shop and we probably won't use this in our production code. The benefit of target-typed expressions IMO is that it changes property syntax from: public List Foos = new List (); to simply: public List Foos = new(); It may seem subtle, but if you write C# you see this pattern constant…

top level is mostly going to be nice when teaching new programmers. You can just get on with hello world and now have to type all this boiler plate and explain why you have to. But yeah, for "real" programs it is probably irrelevant. But who knows, maybe we will find a use for it. I am mostly excited about the sort-of option type getting rid of nulls option.

[deleted]

Re: C# 9 top-level programs and target-typed expressions

#120

I think that C# is underrated. Although TypeScript is my default language choice for most programming, C# / .NET is my choice for cases where: - high performance is important - or interop with native libraries is required (because C#'s DllImport attribute makes that super simple) Another benefit is that C# is syntactically similar to TypeScript (they were both designed by Anders Hejlsberg after all), so switching bet…

A bit of a tangent but is it possible yet to compile C# to native code easily (like calling a normal compiler on the command-line)? Last time I checked I needed to jump through a bunch of hoops through Visual Studio, and create some XML or other nonsense. I don't get why they've made it so hard compared to just compiling managed code.

On Windows using .Net Core makes this fairly trivial.

You basically install the .Net Core SDK and then run these commands to create your first executable:

  dotnet new
  dotnet build
  dotnet run
And I suspect it is the same on the other platforms

Here is an simple console example with more detail: https://www.zeusedit.com/phpBB3/viewtopic.php?f=5&t=8135

Post reply on HN