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
12 views

Refactoring c# 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
45 views

switch vs if, 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
31 views
1
vote
0answers
25 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
19 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 ...
0
votes
0answers
16 views

How do I calculate marks of Online exam in c#? [on hold]

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
84 views

How do you name a something as approximately equal?

Let's say I following have code: ...
0
votes
1answer
18 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
39 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
45 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
77 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
21 views

Can anyone walk me through the logic of this algo for the task? [on hold]

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
29 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
217 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
14 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
21 views

Script to spawn animals according preset % chances [on hold]

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 ...
7
votes
2answers
147 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
0answers
41 views
+50

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
512 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
50 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
47 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
64 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
40 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 ...
-4
votes
0answers
37 views

Facing max pool size was reached error, is there any connection leak in the below code? [closed]

The actual error is as shown below Exception GetPTExceptionStatus,13142 System.InvalidOperationException: Timeout expired. The timeout period elapsed prior to obtaining a connection from the pool. ...
0
votes
0answers
43 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
62 views

Inheritence Cleanup

I have the following interface ...
3
votes
1answer
100 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
0answers
98 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
352 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
104 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
107 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 ...
0
votes
1answer
43 views

Map a hierarchy of nested DTO objects to a list of business objects [closed]

Consider I download my data into this data structures: ...
7
votes
2answers
477 views

Evaluating Parser State

The "parser state" of a module in rubberduck can be one of several values: ...
3
votes
2answers
39 views

Calculate GS1 / SSCC / UPC check digit

I try to write a function which calculates the check digit for shipping label based on the algorithm provided by GS1 http://www.gs1.org/how-calculate-check-digit-manually Version 1: my first try ...
0
votes
0answers
41 views

C# - Separating construction and initialization when serializing a class [closed]

I am currently working on a method to have custom control over the way my classes are serialized. All serializable classes have an interface and they all serialize themselves to an intermediate class ...
-2
votes
5answers
114 views

Finding dice roll results in a combinable list of numbers

This code takes a selection of numbers between 1 to 9 which could be 1,2,3,4,5,6,7,8,9 or 1,2,4 or ...
4
votes
2answers
83 views

Stitching Linq with if blocks

I recently learned about Linq's deferred execution and a little clearer understanding of IEnumerable. I came back to some code that I had written and decided to change with Linq extension methods. ...
7
votes
4answers
474 views

C# SMTP notifier client

I've come from a PHP background and I'm really trying to unlearn the bad habits I acquired from not doing things properly with PHP through my own lack of understanding.. I'm looking to advance my ...
0
votes
1answer
74 views

Storing data bytes into properties

From the related questions here, I've found this and this answers, both of which suggest Replacing Conditional with Polymorphism, are probably what I'm looking for. However, I'm not sure if ...
0
votes
4answers
119 views

Remove “b” and “ac” from a given string

I coded this solution for this problem: Given a string, eliminate all “b” and “ac” in the string, you have to replace them in-place, and you are only allowed to iterate over the string once Seems to ...
2
votes
2answers
66 views
+50

Copy Data from Informix to SQL Server

The following method copies data from Informix db to SQL Server db and it's so slow, I want to refactor it so it could be more readable and faster: ...
1
vote
0answers
40 views

An Extended WebBrowser Control

I needed the ability to do a few extra things with a WebBrowser control on a .NET Windows Forms Form, and I found it needed some updates. So, I made a few. I added ...
4
votes
1answer
69 views

Implementing Binary Tree using Queue in C#

I am in the process of learning data structures and I am trying to implement Binary Tree using Queue in C#. Below are my Tree implementation classes. ...
3
votes
0answers
58 views

Genetic algorithm to arrange rooms in a house

I am an architecture thesis student in my final year and I am developing a piece of software that, ideally, should design houses for me based on certain input. I got the program to work when it was ...
2
votes
2answers
101 views

Take a result set and organize it into a dictionary

I'm trying to take a result set and organize it into a dictionary then assign the dictionary values to variables that are publicly accessible from my controller. My issue is I have to check if there ...
6
votes
2answers
320 views

Generic extension method that will attempt to parse a string and return it's value or default(T)

So I got sick of several things about the way TryParse works. I implemented a generic ParseOrDefault function using reflection. It appears to work as expected, but I'm not fool enough to say my code ...
2
votes
1answer
77 views

C# data class with public auto-implemented properties with constructor that specifies each

I have a dll and an executable which both deal in configuring certain things for a much broader software solution, and the code below in particular is directly meant for database configuration. (Here ...
3
votes
0answers
39 views

MSTest Data Driven Test Inline Data

Background: Didn't what to have to reference bulky 3rd party lib for inline data driven tests and wanted to use standard MS testing framework. Created helper ...