C# is a multi-paradigm, managed, garbage-collected, object-oriented programming language created by Microsoft in conjunction with the .NET platform.
-2
votes
0answers
7 views
What Im I doing wrong ??Error code CS0161 . [on hold]
I cant seem to fix this problem Error code "CS0161 Form1.SquareRoot(double):not all paths return a value" The Word squareRoot in the "Private double SquareRoot(double x)" underlined in Red.
public ...
2
votes
1answer
59 views
Simple class to let a thread make a clean work
I was working on the last days with threads and I didn't want to use ugly methods like Abort(), etc.
So I did a simple class which does use one of the most ...
1
vote
3answers
79 views
1
vote
2answers
197 views
Simple Tic Tac Toe
I have written a simple Tic Tac Toe game in WPC C#. I am just a beginner and learning. Could you tell me if there is something wrong with my code / could be done better? I am pretty much satisfied ...
2
votes
0answers
35 views
1
vote
0answers
11 views
Extension for BindableBase that can dispose the old value of a property if that property implements IDisposable and is not null
I am interested in hearing opinions on this. I need a way to dispose the old value of a property in a way that's compatible with BindableBase. Specifically, I have ...
4
votes
1answer
28 views
Minimize the console window to tray
I have a small console application that runs a very long task and I would like to hide the console window when I click on the minimize button but keep a notify icon in the system tray so that I would ...
3
votes
3answers
68 views
Download function
I wrote a download function and I wanted to know if my code clean, readable and maintainable, or if I could make things easier. Please tell me if this function could be used in the real world.
...
3
votes
0answers
31 views
Unit Testing Input Class in Monogame
I'm new to unit testing, and to learn, I've decided to "contribute" to Monogame to help with their testing efforts. The issue at hand is to test the input device classes. I've started with the GamePad ...
3
votes
1answer
27 views
Buffered read from a large list
There is a large list of email addresses and there is a limitation of max 100 email addresses to process once. This is the code I have written.
...
2
votes
0answers
19 views
Supporting all closure options in WinForms MVC application
I have a WinForms MVC application that uses Ninject for it's Dependency Injection (DI) / IoC Container. I have build quite a nice framework that allows the main shell (which uses a Docking Container ...
2
votes
1answer
63 views
FindTwoSums using Tuple
I am writing a function that, given a list and a target sum, returns zero-based indices of any two distinct elements whose sum is equal to the target sum. If there are no such elements, the function ...
7
votes
10answers
1k views
Writing an anagram efficiently
I know this question has been asked before now but in Python. Recently, I set out to write an anagram in C#. For instance, orchestra can be rearranged into carthorse and the anagram should not have ...
4
votes
3answers
95 views
Composing and executing a customer search
I was wondering if someone could help me refactor this code. Although I know this looks bad, it works. Now I would like to refactor it so I would respect the open/closed principle in SOLID. Let's say ...
4
votes
2answers
81 views
Hangman Game in windows forms
today I created a simple hangman game, which has 10 different categories with 10 words each. The words order is being randomized each time you pick a category. You have the chance to pick a wrong ...
0
votes
3answers
49 views
Counting occupants in each HouseHold provided large file of comma seperated personnel records
I was given the below Exercise as part of a coding Exercise to do at home for a technical interview, and I did not get through past this round.
I would like to get some input on what i could have ...
0
votes
1answer
23 views
AES 256 FIPS compliant encryption + HMACSHA256
I created an Encryption class that encrypts data and decrypts it using the AesCryptoServiceProvider class with an HMACSHA256 ...
7
votes
2answers
145 views
First C# program (Snake game)
I've just started out using C#. I've used Scratch (drag and drop programming for kids) for quite some time. Since Scratch didn't have classes and methods I have a feeling this code could be a lot more ...
1
vote
1answer
41 views
Unit test with Moq callback anonymous function
I have the following unit test that is testing predicate logic in a repository (Note: mockOpportunityRepository.Setup):
...
3
votes
2answers
74 views
Creating a new camera stream
I'm currently in the process of refactoring some code and I was wondering if I should use switch or if-else for the is code:
...
-1
votes
0answers
39 views
Need help improving an Inefficient Travelling Salesman Problem with Genetic Algorithm [on hold]
Need help in improving my TSP program.
City Class
...
1
vote
1answer
50 views
Login page code enhancement
I am starting to learn ASP.NET, and I am designing a page for an admin to login and do some stuff. I have the username and password for the admin stored in Web.config (Is that a good practice?).
...
1
vote
1answer
28 views
Refining an ASP.Net MVC VeiwModel for a Table to display worked hours
I am writing an ASP.Net MVC app which has a page that will display a standard table which will contain a person's hours for the week. The basic structure of the table would be a 7 column, muti-row ...
-4
votes
0answers
32 views
0
votes
0answers
21 views
How do I calculate marks of Online exam in c#? [closed]
On onclick event of the button , I’ve fetch the controls form the aspx page, and further I’ve used if statement in order to see which radio button is active and have store the corresponding value in ...
2
votes
1answer
93 views
0
votes
1answer
22 views
disable other defualt row- Entity framework
I have a table that name is Store , In Store Table , just one row can IsDefault=true at ...
2
votes
1answer
40 views
Middleware for a client
I'm developing a middleware for my client and it's found that there are some delay when executing the process. We are currently investigating what's the exact causes of the issue, from architecture ...
1
vote
1answer
49 views
Extension method to format properties that are not null and not empty
I'm trying to work with the following class, which is inside a library I currently cannot change:
...
0
votes
2answers
92 views
Validating input values in C#
I began studying C# 5.0 a few days ago and am trying to avoid duplicated code for validation of input values.
...
-4
votes
0answers
24 views
Can anyone walk me through the logic of this algo for the task? [closed]
Here is the task itself. Cannot wrap my head around this algorithm. Could there be a more elegant solution for the task? Here is a solution (math) to an almost identical problem.
...
3
votes
1answer
30 views
Unity3D DirectionalSprite
I've created a simple utility class for use in my Unity2D project, which allows a Sprite to have separate sprites for when it is facing East, North, West, or South (that's the order that z-axis ...
5
votes
2answers
227 views
Extracting values from dictionaries where the keys match
I have two Dictionaries with around 65,000 KeyValuePairs each. I used foreach and if-else statements to compare them and get values, but it goes very slow. How could I optimize my code and gain more ...
0
votes
0answers
18 views
Prism 6 Popup Window with EventAggregator to replace a service
I have a WPF project with Prism 6 and EF6. In my project I have a MainTabModule which has ...
0
votes
0answers
25 views
Script to spawn animals according preset % chances [closed]
I have spawners for animals scattered across the terrain in my game. The idea is to have animals spawn only when a player is within range of the spawner but not if there are too many animals in a ...
8
votes
2answers
163 views
Can I stop validating email addresses now please?
Writing code to validate emails is a thing I don't like. It's usually pretty pointless as there's there is actually no right solution, so it leaves me with a certain sense of existential dread.
I've ...
1
vote
2answers
74 views
Faster copying of images to change their PixelFormat
I have the following code below that creates a new Bitmap object the same as the original but to ensure that its PixelFormat is ...
6
votes
3answers
518 views
A reference source for primes up to 64K (for unit tests)
In order to code the tests for my number theory library (a collection of routines that proved handy for coding challenges) I needed a reference source for primes up to 2^16.
I did not want to ...
1
vote
1answer
51 views
WebAPI Handling fire and forget exceptions
This is a fire and forget task from within an existing WebAPI service. The code below simply sends a log event (might be that a client has connected to the service to perform some task) to another ...
2
votes
0answers
50 views
Retrieves Remote Certificate, displays Validity
I'm a Windows sysadmin who is new to C# and "professional" coding. My background is in VBScript ("get it done") and I've apparently built up a number of bad habits. I'm hoping a review of the ...
1
vote
0answers
68 views
Repository pattern implementation
I'm in the process of delving into different design patterns and trying to implement them into my daily work routine.
I come from an unstructured world of PHP and not understanding how to utilize it ...
0
votes
1answer
43 views
Bundling JavaScript resources for an MVC app
This is my first MVC app. I'm looking for best practice feedback on how to best bundle the files that I need, the order to bundle them, the placement of the @render ...
0
votes
1answer
53 views
Func and Action
I have got two generic methods to call against a service. Depending on call, some methods return an object (passed in params), some don't (void). Can this be further improved? I have got to this point ...
0
votes
0answers
45 views
LINQ SQL query to display the status of tracked computers
This is my existing LINQ SQL. At the moment it works, however the using the coalescing operator for null results on the "let" clauses make me feel like I'm violating some sort of unwritten rule. Is ...
2
votes
1answer
63 views
3
votes
1answer
101 views
Two similar methods to process a queue of messages
I have two functions with loops that behave nearly identically, but with some key differences. As a consequence, most (but not all!) of the code in the functions is repeated. I can accept this ...
2
votes
1answer
120 views
Delimited file parser
This is some code I've cobbled together that reads a delimited file. If the user is able to tell us some stuff about the file, it uses the supplied information. Otherwise, it tries to work stuff out ...
4
votes
3answers
353 views
Simple Q&A game
I just wanted to get some criticism on my programming to make me better. I made a game in Unity, just a simple question and answer game.
Demo
...
3
votes
1answer
107 views
Runtime compiler performance
I've been playing about with runtime compilation to allow me to get/set runtime property values in C# and so far I have come up with a class.
This allows me to write code like the following which ...
0
votes
2answers
113 views
Create an array with random numbers
private static byte[] GenerateData(long size)
{
var result = new byte[size];
new Random().NextBytes(result);
return result;
}
Is it good, robust and ...