C# is a multi-paradigm, managed, garbage-collected, object-oriented programming language created by Microsoft in conjunction with the .NET platform.

learn more… | top users | synonyms

0
votes
0answers
19 views

Extension method to find VisualChildren of multiple Types

I created an extension method to return a List of UIElements where the returned elements have to match with one of the ...
2
votes
2answers
25 views

Loading settings from a file to a dictionary

Today I coded a class to get settings from a file and to load them in to a dictionary. Please post and feedback, improvements and changes, no matter how big or small, as long as they are actual ...
1
vote
1answer
52 views

C# Encryption algorithm

I am using CTR mode (it is a cipher in itself) in this code below. I just wanted to see what you guys thought about it before I finish it. (Yes, I know that the plaintext length and key length must ...
0
votes
0answers
16 views

Refactor two methods with only one little different for update or insert a (IoT) device into database

How could I refactor code below? So you can see I've two times the same methods where only an other method is called. In Service.Insert(), I call ...
-2
votes
0answers
24 views

Trouble loading font in Monogame [on hold]

I'm trying to load a font in Monogame, and I've downloaded the font I would like to use. It is a .ttf-file named Legacy.ttf. I get the unhandled exception stating: "Could not load Legacy asset as a ...
2
votes
1answer
54 views

Char Trie and scanner in one

This is from the Resin codebase. It is fast at lookup but I could use some help making it faster at buildup. Loaded with 210K words, it looks up pretty much any node and its descendants in zero time. ...
1
vote
1answer
59 views

Remove nested if statements

Hi I'm writing a project, and the part I'm doing now is getting bloated real fast. How can I remove this nested if statements, but still have the same behaviour? It would be nice the the resulting ...
0
votes
0answers
20 views

MVC application internationalization using a database provider and dependency injection

Following Nadeem Afana's article about how to include internationalization into an MVC application, I have introduced i18n into one of my MVC applications. These ...
1
vote
0answers
57 views

Tiny calculator using dependency injection and inversion of control

I've started to learn very interesting concept of DI, IoC and related stuff. I have decided to learn it using simple application, very tiny calculator (only basic functions: add, subtract, multiply ...
1
vote
1answer
33 views

How do I properly dispose of my dataset?

I am getting a compiler warning when running my code analysis. It is CA2202. It is saying that I have not properly disposed my dataset through all exception paths. Here is the code: ...
0
votes
1answer
36 views

Parallel for each with a try catch and Refactor

I am busy creating a file processor that needs to get some files from an Ftp client download the file and save the data into the database. I have a two part question. How can i refactor the code to ...
0
votes
0answers
13 views

Improving a hand rolled Select tag with OptGroups

I am working in asp.net. The asp:dropdownlist does not have an option for optgroups. I attempted to roll my own select using HtmlTextWriter but it feels flimsy at best. The following code works, ...
2
votes
1answer
45 views
3
votes
4answers
89 views

Copying file dependencies

I have written the following code, and it works great, but I'm not satisfied. I really love the book "Clean Code" by Uncle Bob and I try to apply all his principles when coding, but I'm having a tough ...
-2
votes
0answers
30 views

math expression evaluation in c# [on hold]

I have a math expression '(M1-M2)*2' as an input where M1, M2 has data points from two different CSV files. I need to implement the expression on clicking a button 'calculate' which reads data from ...
1
vote
2answers
657 views

Which is correct : Open one Connection for inserting List of objects or open connection for every single insertion?

I have written the following method twice but I don't know which is better from performance perspective, code design and best practice. First: ...
1
vote
1answer
45 views

Performance issue in generic sql utility

I recently working in .Net field and under circumstances had to write a program to execute sql from external source file.I have written the code and works fine but when it goes to Production server,It ...
3
votes
1answer
48 views

How to optimize the algorithm that extract all pairs of numbers from collection of numbers, which sum matches the particular number?

I had to write the method that extract all pairs of numbers from collection of numbers, which sum matches the particular number. My code is as following: ...
1
vote
0answers
31 views

Add transactional Units of Work to incorrect NHibernate usage (microsessions, single object actions)

This code is part of a quite huge repository using NHibernate in a wrong way: no units of work, but microsessions for every object loading and saving (ignorant of Persistence Ignorance, coded like ...
7
votes
2answers
154 views

Exporting a UserForm from the VBE… and working around API bugs

Rubberduck has been using an extension method to export code files, notably for source control purposes. While testing source control, I ran into a weird bug in the VBIDE API, which caused UserForm ...
3
votes
1answer
124 views

Bitwise operator guide

I'm developing a console app which is supposed to teach how the bitwise operators in C# work. It will include tutorials, training fields and all that good stuff. I have a problem with the naming of my ...
6
votes
1answer
105 views

Bare-bones C# MJPEG stream decoder implementation

I tried to prove to myself that MJPEG stream decoding can be accomplished using bare-bones .NET. So I wrote a class that decode MJPEG streams, trying to keep tips in mind: No allocation, except the ...
-1
votes
0answers
21 views

Am I using ninject nested named scopes correctly? [on hold]

I want to have a hierarchy like: ...
5
votes
1answer
130 views
+50

Finding local C# servers on a Java client using UDP and reactive extensions

This program uses UDP broadcast to find app servers on the local network. When a server receives a client broadcast, it sends a port (integer) to the client which will later be used to create a TCP ...
1
vote
1answer
69 views

Implementing Entity and Component in a game engine

I'm currently creating a game engine for my personal project. And I'm currently implementing Entity and Component System. Classes and Interfaces Definitions Here the classes and interfaces that ...
1
vote
0answers
17 views

Custom Web Api asynchronous filter implementation

Following the tutorial from Filip W's blog, I've ended up creating my own implementation for a custom ActionFilter. This logs the execution name, action, parameters and elapsed time of every ...
1
vote
0answers
41 views

UI code-behind for managing employees

I have a form code behind and it has what are called "Common Utilities". Basically the original author made a super class that is embedded into the main form code behind. What is the best way to ...
-1
votes
0answers
22 views

using static methods in a class [closed]

I am writing a method to get data from database using third party assembly. Is it good to declare the method as static as below, because there are no instance varialbes. ...
0
votes
1answer
39 views

Long running in-process Publish/Subscribe class

I have a Pub/Sub class that will call Notify() when published and that Notify() could take around 10 seconds, so I need to make ...
1
vote
1answer
103 views

Calculating all possible Knight turns (Chess)

I'm creating a console application that takes as input starting column and starting row, also the ending column and the ending row and it's going to output all the possible way's to get to that point ...
0
votes
2answers
92 views

Hangman in CSharp

I've created a simple Hangman game (not finished yet). What could I improve? (This isn't intended to be object-oriented but suggestions on that are also welcome.) What are its flaws? Here's the ...
5
votes
1answer
48 views

Serializing (and deserializing) basic mesh using JSON.net

In order to improve my c# (which is fairly basic at best) I decided to try to serialize a simple mesh to a file using the JSON.net library. Simple mesh in this case means an array of vertices and a ...
-1
votes
0answers
21 views

Combine result of 2 select queries for main query in LINQ [closed]

I tried searching for the answer of my question but I did not find one. Please help me find correct keywords if this question has asked multiple times. I am trying to see how can I combine result of 2 ...
1
vote
0answers
22 views

Resize image from StorageFile

I have created a function that will take as a parameter a StorageFile and return a WriteableBitmap. I use this data type so that ...
3
votes
2answers
93 views

How to check a static class and its members are thread safe or not?

I'm new to parallel programming concepts. I'm trying to implement fire-and-forgot kind of method in my project. Somebody please evaluate the below code & let me whether this is thread safe or not. ...
-2
votes
0answers
30 views

Make the method thread safe in C# [closed]

Hello i have a method which is not thread safe. The method is: ...
3
votes
1answer
59 views

UDP Server Design and Performance

What I'm doing I am writing a server to work as my games backend. The server is being written in C# using UDP as the protocol, while the game is in C++. The biggest thing I've been focusing on was ...
31
votes
7answers
5k views

RPG Currency System

I just spent the last few days constructing the currency system for my game, and was wondering if you guys had any suggestions on how—if at all—I could improve it. Before I show the code, let me ...
4
votes
1answer
81 views

Detect and Fix Switching over an Enum Without Handling all Members

VSDiagnostic's latest refactoring and code fix detects when a switch does not contain case statements for each of the ...
1
vote
0answers
36 views
+50

WPF Track child collection validation errors

I have a need to get notified about validation errors that occur in a child collection of my ViewModel. For validation I use the ...
4
votes
2answers
157 views

Multiprocess, multithreaded read write on a single file

I've got a job to create a library that would be able to support multithreaded and multi process read and write to a single file. On that single file we would store C# models in an array in JSON ...
1
vote
0answers
44 views

Priority message sending

We have created a message queue system using priority messages. The idea behind this code is as follows: We have a list of clients. All clients know if (and what kind of priority) messages they have ...
1
vote
1answer
68 views

Repository Pattern universal application

When I started learning Repository Pattern with Unity few days ago I was under impression that the main benefit of this pattern is the separation of data layer from the business layer. In other ...
2
votes
0answers
31 views

Controlling a drone in Unity3D

I'm currently building a game called "Drones! Attack!", and I needed a drone controller that the player can use. It's currently very simple and only supports a small amount of actions, such as: ...
0
votes
0answers
36 views

Distinct List of attribute values from XML, using a pre-defined set of attribute names

I have an XML stream that looks like the following (attribute and node quantity , and node depth reduced for demonstration purposes.) ...
3
votes
1answer
71 views

Returning an IEnumerable using Linq-to-SQL which is then bound to a GridView

This function works, but it's really really slow and the generated SQL is gargantuan and horrible to look at. It's also very expensive to run when it shouldn't be. ...
1
vote
1answer
31 views

Multiple emails and attachments, reusing memory stream

I am generating a pdf form based on user input from an MVC website form. The pdf is genrated using the Foxit .NET SDK, then attached to three separate emails, generated using Postal. It has been ...
3
votes
0answers
41 views

Event delays for a Monogame project

I am making a GUI for my C# Monogame project. So since this was the first time I ever made a GUI that is not winforms-based I took a wrong approach in making it and thus I decided to change it ...
4
votes
1answer
86 views

Lazy prime number generator

There are multiple Project Euler problems (e.g. 7, 10) that deal with prime numbers. I decided make a reusable solution that could be used for most of them. I wrote a method to generate an infinite* ...
0
votes
0answers
46 views

Pass several classes as one parameter with Poker user controls

I have two classes that hold some info about the user. One holds the data, the other one holds the controls info. Now I need to pass both of them as a parameters to a method. However they are ...