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

General feedback on Web API using Repository / UnitOfWork

Looking for feedback on a repository I setup based on a blog post I read here: https://codefizzle.wordpress.com/2012/07/26/correct-use-of-repository-and-unit-of-work-patterns-in-asp-net-mvc/ I have ...
3
votes
1answer
38 views

WinForm Calculator

I'm looking to get this cleaned up. ...
0
votes
0answers
20 views

Creating a game of Checkers in C# [on hold]

So I am having a tough time understanding how to get the program to read my inputs via button presses for each cell. It's a more of a primitive checker game, but I seem to be getting super confused ...
2
votes
2answers
33 views

MVC N-Tier Architecture

I am working on a new MVC web application, so the project is in early stages. I have created 4 projects. Let me explain what they do: Common --> contains all my DTOs, enums helpers, ViewModels ...
-1
votes
0answers
14 views

implementation interface concept for making a simple calculator in c# [on hold]

how to implement interface concept for making a simple calculator in c#. ...
1
vote
2answers
88 views

Check for null/empty in dictionary

I am doing the following about 10 times with other strings, so the code is duplicated. How can I refactor this? queryWhere is a ...
2
votes
1answer
135 views

Steganography - images within images

I'm currently learning about steganography at UNI, so I decided to try it. I was looking for some feedback on the way I decided to do it. Normally, you would change the LSB of the RGB channels in a ...
1
vote
1answer
23 views

MVC4 Unit Of Work with Entity FrameWork

I am designing a new asp.net MVC4 application. I know that context class generated by EF is Unit of work and Dbset is the repository class. I am just avoiding the extra abstraction. I want to know ...
0
votes
0answers
32 views

Return Class based on Interface and Enum [on hold]

I have a number of classes that implement one or more interfaces. I need to be able to retrieve the correct class corresponding to a given Enum value, but as a type of a specific interface. Classes ...
1
vote
1answer
41 views

Dependency injection thread safety

Is it OK to mix different lifetime of ISerializer and ICacheProvider in this case? I am using Unity DI. In this case, whenever ...
2
votes
1answer
40 views

Throttle actions by number per period

I want to throttle asynchronous actions at a specific maximum rate of n actions per t period, and have pending actions wait until there is a free slot (rather than drop them). I want to receive the ...
3
votes
1answer
66 views

Split string by substring without using String.Split()

The Aim Since I very rarely write code to do things other than business logic anymore I've set myself a challenge: Split a string into a list of substrings by splitting on a matching string, without ...
-1
votes
0answers
15 views

C# NetworkStream.Read doesn't take ulong parameter but only int [on hold]

We want to send an byte[] of 8 000 000 bytes for exemple, but the function NetworkStream.Read can only accept int values, how can we get all the data? we try to put ulong in this function but it's not ...
7
votes
3answers
135 views

Generating Unique Colors

I just wrote a small class that generates perfectly unique colors(or that is the plan anyway). I found the original index shifting snippet online, and was just wondering if it could be improved in ...
6
votes
3answers
437 views

Function that convert decimal to binary

I have a function that converts an integer to its binary representation. I am wondering if there is any way I can improve the function. ...
2
votes
2answers
43 views

Return existing values inside database

Here's a method inside my controller that reads the values of angle and point data from my database. Then it grabs the data and adds it to a new list and sends the JSON to the view. I can't simplify ...
6
votes
3answers
65 views

Color-coded console output

I wrote this Console.Write function to use in my applications where I need to easily color-code output. Example syntax would be: ...
4
votes
1answer
57 views

Classes for reading data from Sql Server into objects

The following is a set of classes that read metadata from Sql Server tables and populates local objects. It works, but I feel like there's too much duplication happening and too many places changes ...
3
votes
1answer
87 views

Using composition instead of inheritance

I have been using Entity Framework 6, AutoMapper, ASP.NET Web Api and hit a few problems along the way, each time it was recommended that I could change my code from Inheritance to use composition ...
1
vote
1answer
59 views

Thread safe double buffered cache

I want cache object for one value, which have two expiration limits. One "soft" limit indicating "value is old, but is still valid, but is good time for reload the value". And one "hard" limit ...
0
votes
0answers
22 views

How to best handle unused pointer when calling C++ from C#? [migrated]

I have code in C++, which I will call from C# via interop mechanism. In my C++ code, this is my class structure ...
7
votes
0answers
65 views

Fun with CallerLineNumberAttribute: clever hack or terrible idea?

One fun feature that was added (fairly) recently in .NET is the [CallerLineNumber] attribute, which, in conjunction with ...
0
votes
2answers
57 views

Comparing values in 2 DataTables

I'm processing 2 DataTables: SSFE: Contains the values I want to find FFE: Is larger, smaller or equally large as SSFE, but does not necessarily contain every value of SSFE The values I need to ...
0
votes
2answers
29 views

Stripping time information in a DateTime object [on hold]

Is there any better way to strip the time information in a DateTime Object than creating a new DateTime Object? For example, if I just want today's date and not time, is the only way is to do the ...
1
vote
1answer
32 views

Exposing includes to client over webservice for database queries

I am using a CQRS type patter for querying data in my application. I am currently using entity framework to connect to the database. ...
3
votes
1answer
66 views

Extension method to do Linq Lookups

Does this extension method contain unnecessary work? - Thanks for reviewing Scenario - A series of tables are Key-Value pairs (Int "Id" / nvarChar "Title"). This extension method "dots-off" any ...
2
votes
1answer
45 views

Generic classes with inheritance/equals/comparison operators

I would like to greatly reduce verbosity of following code fragment. What I'd like to do: Reduce number of occurrences of MaterialRangedParam<Value> and ...
3
votes
1answer
42 views

Getting a single value from the DB

This is supposed to get a single value from the DB. What should I consider next? How can I upgrade it? ...
1
vote
1answer
53 views

Receiving all data comes from web in system.net.socket

I listen on a port via multi thread async socket. That port receives requests over XDomainRequest. I received the complete data each time till now but I don't trust this code because it may not work ...
10
votes
6answers
3k views

Given two int values, return the one closer to 10

I did the exercise below to practice. Can someone help me to shorten or improve the code in a simple way for a beginner? The exercise is: Given 2 int values, ...
1
vote
2answers
69 views

Task scheduler for a particular application

This isn't meant as a scheduler for just any job. The job that I need to schedule here is very specific for an application I'm writing for one of my clients. The scheduler will run as a console ...
4
votes
1answer
71 views

Insert String array as label content in datagrid row through radio button

I have written some code for inserting a label at runtime that has its content set to a string array into a datagrid row. All of this will initiate when certain radio buttons are checked. The code is ...
0
votes
1answer
95 views

Inserting employee records

There is nothing wrong, but is there any other nice way to re-write this program? ...
-1
votes
1answer
40 views

Piggybacking namespace pros and cons [closed]

I was wondering of there are any disadvantages to piggybacking namespaces in c# when creating extension methods. So for instance , I have a class being referenced by the main project as well as the ...
0
votes
2answers
119 views

Seemingly redundant conditionals…or not?

I'm working on some code that has the following pattern of conditionals inside it. It doesn't look great, but it doesn't look terrible. Please, shed some light on the underlying reason this is not ...
-4
votes
0answers
21 views

image to array / array to image, very strange display behaviour [closed]

I am creating a custom Byte[] array from an image, Then i turn back that array into an Image and display it into a PictureBox. ...
8
votes
4answers
805 views

Basic text-based rover game

I've made a small "rover game" similar to this one, except made in C#, using OOP, and prettier menus. Here's how it works: There is one Rover class which is ...
6
votes
4answers
105 views

C#/.Net 4.5 - Number Guessing Game

I'm currently enrolled in an introductory C#/.Net 4.5 course and one of the things I want to focus on is the quality of my code. This is the first assignment our instructor had us do, the ...
10
votes
4answers
647 views

Imaging with getPixel() and loops

I wrote perfectly working code that reads an image, and then does a kind of threshold on it by zone. If the zone has too much white then it turns all the zone into white, otherwise it turns into ...
4
votes
0answers
75 views

TPL inside Windows Service C#

I need to perform few tasks inside a Windows Service I am writing in parallel. I am using VS2013, .NET 4.5 and this thread ...
5
votes
3answers
111 views

ImmutableList implementation in C#

I tried to implement an immutable list. ...
8
votes
4answers
809 views

Printing an Alternating Pattern to the Console

For this assignment, you will create the pattern of a chess board that is 8 x 8. Use X and O to represent the squares. Create the appropriate nested looping structure to output the ...
2
votes
2answers
55 views

Users and friends query with retry, returning JSON

I am new to Azure and SQL. I have the following function that is part of a larger Web-API which is hosted on Azure and is querying an SQL Server database that is also hosted on the Azure platform: ...
2
votes
2answers
73 views

Class for easier to read IProgress<Class> handling (Version 2.0)

This is an update to my question Class for easier to read IProgress handling and includes the suggestions from @svick, with one exception. It was also suggested to change the setter for ...
4
votes
2answers
56 views

Extracting a number from provided URLs inside a text file

I need to extract a ID (int number) from a Url. Example: http://www.example.com/foo/bar/12345 For this I wrote 4 methods where the first one ...
10
votes
1answer
160 views

Here's my interface, so call me …maybe

I'm inspecting VBA code to find obsolete code constructs - namely explicit Call statements, like this: Call DoSomething(42) ...
2
votes
1answer
41 views

Regex in combination with file compare

I have made a funtion to compare text files line by line, where timestamps and jobnumbers are replaced for a identical string. By lack of experience I'm not sure if this is the best way to do this. ...
4
votes
1answer
42 views

C# Chat - Part 2: Client

This is the second part of a multi-part review. The first part, the server for this client, can be found here. I've been building a simple C# server-client chat-style app as a test of my C#. I've ...
3
votes
2answers
49 views

Composing terminal control sequences

I've seen everybody claims the nested ternary to be an evil even when an operation couldn't be written with switch-case; and here's even more, my code could be easily written with switch-case ...
2
votes
1answer
33 views

Type Name or Alias via Reflection for TT Code Generation

I was working on some TT code generation to get rid of mundane C# codings in VS2013 Express Edition, and after researching online, created the following helper methods to facilitate Type declarations. ...