C Sharp

1515 readers
16 users here now

A community about the C# programming language

Getting started

Useful resources

IDEs and code editors

Tools

Rules

Related communities

founded 1 year ago
MODERATORS
51
 
 

Short explanation of the title: imagine you have a legacy mudball codebase in which most service methods are usually querying the database (through EF), modifying some data and then saving it in at the end of the method.

This code is hard to debug, impossible to write unit tests for and generally performs badly because developers often make unoptimized or redundant db hits in these methods.

What I've started doing is to often make all the data loads before the method call, put it in a generic cache class (it's mostly dictionaries internally), and then use that as a parameter or a member variable for the method - everything in the method then gets or saves the data to that cache, its not allowed to do db hits on its own anymore.

I can now also unit test this code as long as I manually fill the cache with test data beforehand. I just need to make sure that i actually preload everything in advance (which is not always possible) so I have it ready when I need it in the method.

Is this good practice? Is there a name for it, whether it's a pattern or an anti-pattern? I'm tempted to say that this is just a janky repository pattern but it seems different since it's more about how you time and cache data loads for that method individually, rather than overall implementation of data access across the app.

In either case, I'd like to learn either how to improve it, or how to replace it.

52
53
54
5
Announcing C# 12 (devblogs.microsoft.com)
55
56
 
 

Lately I've been reading a lot about functional programming principles and how they (of some of them) can be applied in C#. So I came across Language-Ext and CSharpFunctionalExtensions (as well as a few smaller ones). I briefly tried Language-Ext and am liking what I see, but haven't tried the other. I know there's always F#, but I want to explore other options as well.

I'd love to hear about other people's experiences with those libraries (or similar ones). What do you like about them and what don't you like?

57
58
59
60
61
 
 

I came across this video and it's been a great watch with lots of practical examples. As someone who had worked with java, I am in awe with the powerful concepts c# has. Hopefully, someone will find this course useful as well.

62
 
 

I feel like I'm missing something with ML.NET.

As a POC before investing serious computer time. I tried creating a CSV file, 2 columns with 1000s of rows:

Greeting,Reply
My name is Jimmy,Hi Jimmy! How are you today?
My name is Sally,Hi Sally! How are you today?
My name is Mike,Hi Mike! How are you today?

The Model Builder has classification models (I don't believe this is a classification model because I want the thing to be able to predict something new so when it received "My name is Poutine" it will say "Hi Poutine! How are you today?"

I tried anyway and kept getting 0% success on the model.

I came up with another idea, to convert the words to numeric values and then return an array of numeric values.

Doesn't seem like ML.NET can return arrays very easily. I kept getting errors about invalid schema expecting single Key returns rather than arrays.

When I followed up with Bing AI on this it suggested:

Unfortunately, ML.NET does not currently have built-in support for text generation or sequence-to-sequence models. You may want to consider using a different machine learning framework that supports these capabilities, such as TensorFlow or PyTorch.

Am I getting accurate info from the AI? Should I be looking outside of the MicrosoftSphere for this stuff?

Anything you'd recommend?

63
 
 

I have a repo with a bunch of C# projects in it, probably a couple dozen. These projects are shared between maybe seven applications.

I'm looking for a tool that can map out these projects, starting with the application startup projects and draw connections between them showing which projects are referenced and used by what other projects.

Does something like that exist?

64
 
 

How do you all go about validating that there's nothing malicious in your nuget packages?

Is there a best practice for this?

It's easy if the package is from a known source like Microsoft but I'm curious what you do for lesser know people?

I will usually see how many others are using it, probably scan the code in the GITHUB repo. Sometimes if it's a lesser known dev I'll just pull from GITHub rather than using NuGet.

Today however, I was looking at a package and the nuget package itself looks fine but it contains some C++ code that is compiled elsewhere...fine I'll go get that and see. But that code requires CMake and some other 3rd party add-ons which I also have to review.

I'm not aware of any audits on NuGet that would prevent bad people from uploading code. What do you all do to protect the integrity of your software?

65
66
67
 
 

Hello everyone,

I'm excited to announce the official launch of XAML for Blazor, a tool that allows you to leverage your XAML expertise within Blazor WebAssembly applications!

Key Benefits:

  • Seamlessly integrate your XAML skills in Blazor WebAssembly apps
  • Revitalize legacy XAML-based apps such as WPF, Silverlight, UWP, or WinUI
  • Boost your web applications with powerful XAML controls like DataGrid and DataForm
  • You can mix and match XAML and Razor within the same Blazor WebAssembly project, pass objects seamlessly between XAML UIElements and Razor Components, use familiar XAML features like MVVM, Binding, Styling, Templating, Panels, and Custom Controls, and access powerful features like RIA Services, WCF SOAP, PRISM, MEF, and more.

Our goal with XAML for Blazor is to solve the challenges developers face in integrating existing XAML-based applications with web applications, and helping to bridge the gap between desktop and web development.

If you're interested, you can dive right in with these links:

Full disclosure, I'm part of the team behind this project, so I'm happy to answer any questions or feedback you may have!

Thanks, Giovanni Albani CEO @ Userware

68
69
 
 

I've been teaching myself C# for the last 2 years or so. I've got a reasonable handle on a lot of the language/ programming in general. However I feel like I'm massively missing the mark when it comes to debugging.

I deal with a lot of multithreaded and real-time applications that interact with physical hardware. I can set breakpoints and inspect variable values at the breakpoint, step into, step over, etc. But the "autos" and "locals" windows are something I don't understand.

Are there any decent courses/resources that teach me some intermediate debugging skills. Particularly interested in resources that focus on Visual Studio tools (extra points for resources that include tips on VS Enterprises debugging tools, like step backwards, etc.).

Appreciate anyone pointing me in the right direction! I've learnt by feel up to this point, but I've hit a wall and could use some structured docs or courses.

70
71
 
 

I'm looking for a Linear Algebra library to perform calculations for circuit analysis, which ones would you recommend?

72
 
 

Link to GitHub issue: https://github.com/dotnet/csharplang/issues/7009

Link to video explaing it: https://youtu.be/91xir2oUQPg

73
 
 

Hi all! Trying to work with small pet project for myself. So I use few asp net core apps + db in docker and docker compose. And I little confuse about storing configuration (like for logging or db connection etc). Where is best place to store it? Continue use app.json or move .env files (enviroments variables)

I guess .env files more easy to configure f.e. on CI\CD So whatis a better?

74
 
 

There are many YouTube channels that specializes on C#, but not all of them are created equal. So, I thought, it would be good to share the ones that we think is worth taking a look at.

75
 
 

Hey guys,

I'm looking for a complete guide to C#. If it covers basic programming paradigms as well that would be a plus as I have coded a bunch of stuff but am lacking in theoretical knowledge.

I'm definitely open to spending money for a book or something like that. A full course would be outside of my price range though.

Maybe someone has any good suggestions! I obviously tried googling and had a look at microsofts learning resources but without having some feedback as to how good they are it is difficult to choose something.

view more: ‹ prev next ›