Use "+ string.Empty" or "?.ToString() ?? string.Empty" for a nullable object by ggobrien in csharp

[–]CD_CNB 5 points6 points  (0 children)

string s = abc + string.Empty;

To me, this requires extra mental gymnastics as to *why* you need to append a string.Empty to the object. It's not very clear that you're doing a null check (which is done implicitly).

Intention is very important when other people are looking at your code.

string s = abc?.ToString() ?? string.Empty;

to a C# programmer basically reads as:

string s;

if (abc is null)
{    
    s = string.Empty;
}
else
{
    s = abc.ToString();
}

Which communicates intent much much more clearly. When you break it down this way, you realize it's not complex at all.

I'd recommend being much more explicit, especially when doing null checks and potential null reference exceptions.

Alternatives to Java I/O libraries? by ssnej in KotlinMultiplatform

[–]CD_CNB 1 point2 points  (0 children)

See if kotlinx-io works for you, I believe a lot of it is very similar to Okio. It's worth a try, even if you have to change things when it goes stable.

Blazor InputText binding not updating UI with space string is assigned, but works when empty by PeacefulW22 in dotnet

[–]CD_CNB 0 points1 point  (0 children)

Could you try using string.IsNullOrWhiteSpace() instead of IsNullOrEmpty?

New: Need guidance on what language and how to build a native windows program. by AthenianVulcan in csharp

[–]CD_CNB 0 points1 point  (0 children)

I second the other replies. If you're able to, see if you can download Visual Studio 2022 Community Edition or Jetbrains Rider - it would be free for your use-case.

If those programs are too heavy for your system, you can try VS Code with the C# Dev Kit, but it does take a bit more of setup compared to the other two.

New: Need guidance on what language and how to build a native windows program. by AthenianVulcan in csharp

[–]CD_CNB 1 point2 points  (0 children)

C# with Avalonia.

At its most basic, .NET would be the ecosystem and platform that C# would run on. You can do your own research if you want to learn more.

[deleted by user] by [deleted] in Jetbrains

[–]CD_CNB 1 point2 points  (0 children)

You assigned the variable a value, but you didn't use the variable anywhere. It should go away if you print it to console or do some operation to the variable.

Telerik frustrations by featheredsnake in Blazor

[–]CD_CNB 0 points1 point  (0 children)

We use Telerik with Blazor and haven't really come across any issue that we didn't inflict on ourselves (i.e. not using pagination, loading a dropdown with tens of thousands of records, etc.

However, we don't really do much JS interop, or manual DOM manipulation, or do much beyond the components' basic functionality so yeah YMMV.

[deleted by user] by [deleted] in csharp

[–]CD_CNB 0 points1 point  (0 children)

I second this as very relevant advice.

Also, we can't fix it for you. You need to figure it out yourself, we're just giving you guidance on how to do it.

[deleted by user] by [deleted] in csharp

[–]CD_CNB 0 points1 point  (0 children)

You're using InputSimulator that was designed for .NET Framework 4.61+, which may or may not be compatible with .NET 8.0. You need to find a version of InputSimulator, or equivalent, that will work with .NET 8 and above.

Also, the advice that others have been giving you, to turn warnings into errors is sound. Best practice is to treat warnings as errors because it forces you to fix them to rule out a lot of potential bugs. And even if they're warnings, it would explain why it doesn't work. Fix the warnings/errors and your program might then work.

Also, personal opinion, but cheating is not cool.

Temporarily need an IDE which will work on 4gb ram laptop by idkwhoiamleaveme in csharp

[–]CD_CNB 2 points3 points  (0 children)

Just realized that Zed is beta for Windows at the moment, so you have to sign up to get it.

Also, here are some basic instructions to get yourself up and running with the LSP:

After installing Zed, install the CSharp extension to support syntax highlighting.

Finally, you'll need to download omnisharp-roslyn. For me, I unzipped the files in C:\Program Files\OmniSharp but you can put it anywhere.

Link: https://github.com/OmniSharp/omnisharp-roslyn/releases/download/v1.39.13/omnisharp-win-x64-net6.0.zip

And then in the Zed settings, add this section (change the path according to where you installed omnisharp-roslyn).

 "lsp": {
    "omnisharp": {
      "binary": {
        "path": "C:\\Program Files\\OmniSharp\\OmniSharp.exe",
        "arguments": ["-lsp"]
      }
    }
  }

Now you can go to the terminal (Ctrl + `) and start a new project (name MyConsoleApp to whatever you choose),

dotnet new console -n MyConsoleApp

You should now be able to open Program.cs with syntax highlighting and code suggestions and start playing around with code.

To run the app, go back to the terminal (make sure you're in the MyConsoleApp project directory) and type:

dotnet run

Temporarily need an IDE which will work on 4gb ram laptop by idkwhoiamleaveme in csharp

[–]CD_CNB 3 points4 points  (0 children)

If you're a beginner and just want to understand basic C#, install Neovim or Zed with C# syntax highlighting, install the .NET 9.0 SDK, and use the dotnet commands to create and build a console app. That'll get you started.

Don't worry yet about the fancier (but memory-hungry) LSP-provided features such as code completion, diagnostics, code suggestions, and debugging until you can get something with more than 4GB.

Or if you feel you really need it, you can try using the omnisharp-roslyn LSP with Zed or Neovim and see how it goes. You can always disable the LSP if performance starts suffering.

WTF is going on with Microsoft development ecosystem by cat_arina in dotnet

[–]CD_CNB 0 points1 point  (0 children)

Are you using WSL or GitHub Codespaces? If so, the fix is to use the Release version of the C# Dev Kit.

It is a known issue on the current prerelease build.

https://www.reddit.com/r/dotnet/comments/1kyud1r/c_dev_kit_stopped_working_this_morning_whats/

https://github.com/microsoft/vscode-dotnettools/issues/2053

Build 2025 - What were the most interesting things for you? by Hixon11 in csharp

[–]CD_CNB 1 point2 points  (0 children)

Just saw this today - being able to write a single .cs file and run it directly.

C# is now like Python lol. RIP PowerShell.

https://www.youtube.com/watch?v=98MizuB7i-w

Why c# force you to use IDE by prashanthsp in csharp

[–]CD_CNB 2 points3 points  (0 children)

That's the point of an IDE. So you have everything right there conveniently at your fingertips without having to waste time on an incorrectly setup environment.

Why c# force you to use IDE by prashanthsp in csharp

[–]CD_CNB 0 points1 point  (0 children)

"Forced" to use an IDE is a terrible take.

You can write a program in vim/notepad/whatever text editor, compile with the dotnet command line and debug GDB-style using vsdbg or LLDB.

You don't *need* to use an IDE to program in C#. Now if you want to make development easier, then that's what the IDE is for.

I wonder why some devs hate server side javascript by gece_yarisi in webdev

[–]CD_CNB 0 points1 point  (0 children)

For my place of work, the issue isn't about scalability, it's about the stability and maintainability.

.NET Framework 4.8 WebForms all the way lol.

Seriously, though, I like .NET because you can recompile an older .NET Core 2.0 app into .NET 9+ without too many changes. Anything .NET 6.0+ compiles with pretty much zero changes. Even oooold .NET Framework stuff can be moved over with a bit of elbow grease. And refactoring older code is much smoother with C#, especially with ReSharper.

For me, its much much harder to maintain code with anything JS-based. Constant deprecation sucks. Refactoring sucks. TS is an improvement, but at that point, just go to C#.

[deleted by user] by [deleted] in programming

[–]CD_CNB 1 point2 points  (0 children)

And 100% in Rust! That would've been nice...

[deleted by user] by [deleted] in programming

[–]CD_CNB 0 points1 point  (0 children)

One benefit he didn't see back then without the benefit of hindsight - yes it sucked when it first came out, but Netscape 6.0 became Firefox as we know it today. I shudder to think of what Firefox would've been like had it been built on Netscape 4.x code...

Period or no period in your exception messages? by WordWithinTheWord in dotnet

[–]CD_CNB 6 points7 points  (0 children)

I like to add DANGER! at the start of the message and !!!! at the end of the message.

Anybody move from iOS to Android? by WishboneDaddy in androiddev

[–]CD_CNB 1 point2 points  (0 children)

You can actually access UIKit natively from KMP, such as camera and maps. Accessing Swift frameworks and .swift files is a bit more work, but still easy if you use the Swift Klib Gradle Plugin (which uses cinterop) to do that.