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

learn more… | top users | synonyms

2
votes
2answers
29 views

Building Session-Variables from a sql stored procedure

I have been advised to submit my code here by a fellow Stack contributer as it was suggested the code could be further improved; Calling Code and attempt at building session variables: DataTable ...
2
votes
1answer
51 views

My implementation of lexicographic permutation in F# is 3x slower than C#?

Can someone help me with the following micro optimization for the f# code for lexicographic permutation? I have code in C#, which runs 0.8s. As a learning practice, I translated it into F#. However ...
2
votes
1answer
20 views

XML to Windows.Forms.Keys List

It took me a lot of poking around and unit testing to get the code to look like it is right now. So I have a XML file which in part looks like this <FunctionKeys> ...
4
votes
3answers
90 views

Using ref for value types - Is this the right usage or is it weird at multiple levels

I chanced upon this code written by the Solution Architect for a MS CRM project and I am lost for words. Am I going crazy or is this code OK? string returnedOptionSetStringValue=string.Empty; int ...
3
votes
3answers
49 views

GetCommonBaseClass: Readabiliy and Functionality

I have two pieces of they which do almost the same thing. They both return the most common base class of two types. They differ in two aspect: If one of the arguments is null, code A returns null ...
1
vote
1answer
37 views

It there a pattern used to process a same function but assign the result to a different variable regarding to a different condition?

Say I have a code snippet like this if(string.Compare(isStandardFlag,"STANDARD",true)==0) { hearingID = centreSession.standardID; centreSession.standardOutcomeID ...
5
votes
3answers
74 views

LINQ Group query - simplifying

Is there a way of writing this correctly working query more efficiently? I'm asking only to learn LINQ better: var cpuInfo = edgeLPs .GroupBy(k => k.CPU.ID, e => e.CPU) ...
0
votes
4answers
105 views

Proper way to execute parameterized commands within a method

This method allows for the execution of parameterized commands within a DAL class, and I tried to make it as reusable as possible. It works well but it feels a bit verbose to me. Is there a way to ...
1
vote
2answers
49 views

Insert Selected item in listbox using Ado.net and stor proc

I create this class method to Enter Selected Items Form CheckboxList to associated resource I use ADO.net & store Proc to insert data can someone help me to improve it and make to so clean instead ...
1
vote
1answer
45 views

Truncate port number from absolute Uri

We had a requirement to remove the port number from the Request.Url.AbsoluteUr i.e Actual: https://mysitename:443/Home/Index Excepted: https://mysitename/Home/Index The code I used for ...
-1
votes
1answer
77 views

C# constants, is this right usage? [closed]

Is this the right code? public const string Yes = "Yes"; public const string No = "No"; In which cases i should use constants instead of string, in C#
2
votes
1answer
43 views

Dynamic Treenode Creation

I am trying to create a treenode structure based on a database table for a Dungeons and Dragons character creation program I am working on. I have come up with an incredibly confusing way to do it, ...
2
votes
2answers
56 views

Sequential Execution: Orchestrator Pattern

I built a code piece that makes it easy to execute a set of sequential operations, that might depend on the same parameter value (passed across the execution) or might need a particular parameter. ...
1
vote
1answer
48 views

REST-ish API Account Controller - how's it look?

I still have to implement api keys for client auth, but so far this is what I have for users. This was built using WebAPI and SimpleMembership with Forms Auth: Is Authenticated: public class ...
-1
votes
0answers
30 views

Program gives to a word special numerical value. I need help to upgrade my code [closed]

Program checks each letter of the string one by one and calculates the sum of the numerical values of each letter i have applied. I need your help to not let program count value of "i" teller if it ...
1
vote
0answers
44 views

Fastest fill memory with specified 64-bit value

I need to fast fill some memory block in C#, so I wrote something like this (in Ffree Pascal COmpiler + Lazarus in 64 bit mode): // ECX = Ptr64 // EDX = Count // R8 = Value PROCEDURE Fill64 (VAR ...
1
vote
1answer
48 views

Accumulating inner exception messages

Say, there is a class with some methods, that have try catch blocks. I need to accumulate messages from all inner exceptions of generated exception and use throw new Exception(exceptionMessages). I ...
4
votes
1answer
120 views

Is this class too over the top?

In response to my previous question, I've refactored my class quite a bit. I've truncated my class a bit, because I have several methods that are very similar, with the exception of the query for the ...
1
vote
2answers
33 views

A Generic NHibernate wrapper with transactionality

My team and I wrote the following Nhibernate wrapper which gives generic retrieval and save/update functions and a possibility to send a function as a paramater which may contain several save/update ...
3
votes
2answers
98 views

Design Pattern Question/Violating OCP

Is there a design pattern I can use for a situation like below. This is an example I made up to try and explain the situation I'm dealing with currently. I keep having to add new DeviceScript ...
3
votes
2answers
58 views

Reversing each word of a string while keeping the case index

I was given a simple requirement for reversing a string. The requirement is as follows: In any programming language, create an input that accepts “My name is Albert McDonald.” and outputs the ...
0
votes
1answer
77 views

Deep copying objects with circular references

I've found a good example of how to do this in Java and how you can get the same behavior in c#, so I've made made an attempt at it: public class CircularReferenceOne { public int Identifier; ...
1
vote
2answers
82 views

CRUD Menu creation - how best to refactor?

I would like to re-write this c# code so it is easier to understand. Should I create a separate function to configure a menu item? Is there is some kind of using statement so I only need to mention ...
2
votes
1answer
42 views

Working with sqlit and moving functions to class (new programmer)

Hello to anyone that wants to give suggestions, and thank you in advance. Here is the code I am using. Very specifically I am using code review for just that (critical opinions from better ...
1
vote
0answers
32 views

Sugestion on a better way to code this EF update?

I have a block of code that pulls the current menu position and compares it to what users selected, if the selection is different the database is updated with the new selection. As I am still new with ...
2
votes
1answer
48 views

Tuple/Lookup conundrum

I have a list of plans and a list of contacts, and I have to check whether contact.ProviderId matches plan.ProviderId. If they match I need to store in a contactUI the plan.Name Provider to plan is a ...
1
vote
1answer
39 views

Feedback and Advice on my N-Tier Application Architecture

I am working on an application that will use an N-Tiered approach. I would appreciate any feedback and advice on my architecture before I proceed any further. DataLayer (Class Library Project) ...
2
votes
0answers
34 views

Monkey testing a SmartCard library

My definition of monkey testing is basically playing with a program in as if I was a monkey (press every button, unplug things, go in the wrong order..etc etc) So I made a rather simple SmartCard ...
1
vote
1answer
99 views

Code review for an abstract repository implementation

I have a repository abstract class that encapsulates pretty much all of the CRUD functionality: public abstract class DataRepository<T> : IRepository<T> where T : class { public ...
1
vote
2answers
54 views

MySQL GEAR, C# class for ASP.NET project

I've developed my own class in ASP.NET project to access MySQL and make queries, scalars and read the result from it. I want you to review my class and tell me where did I make a mistake, thanks! ...
3
votes
1answer
60 views

Quadratic Primes

This is one of the slightly trickier Project Euler Questions I have seen (Question 27) Considering quadratics of the form: n² + an + b, where |a| < 1000 and |b| < 1000 where |n| is the ...
4
votes
4answers
182 views

Sum of primes less than 2,000,000

I have been attempting the questions at Project Euler and I am trying to find the sum of Primes under two million (question 10) The sum of the primes below 10 is 2 + 3 + 5 + 7 = 17. Find the ...
2
votes
1answer
55 views

How to remove goto statement from iterator

I'm implementing a simple iterator in C# over an xml document, in order to process an xml document in as much a streaming manner as possible. For this reason, I'm using an XmlReader variable in a ...
2
votes
1answer
49 views

Cropping and combining two images on server

I've coded following two methods to combine images that are HTTP POSTed to the server: // Crops two squares out of two separate images // And then combines them into single image that's returned as ...
5
votes
1answer
145 views

smallest number divisible by all numbers from 1 to 20? Project Euler question 5

I'm currently working my way through the questions on Project Euler and I am on question 5. Is this the best possible solution? Any suggestions welcomed! List<int> divisors = new ...
2
votes
3answers
94 views

Largest Palindrome efficiency

I have written an algorithm to find the largest palindrome under a given number, but I am sure my code loses efficiency by creating new arrays in every pass. I am currently learning about efficiency ...
2
votes
1answer
37 views

Code review for a windows form that generates invoices

I have a C# program that I would like to have reviewed. I am new to programming and want to know how it could be improved. It is a Windows Forms project that generates a pdf using the iTextSharp ...
1
vote
1answer
61 views

Improving the CRC code with “unsafe features”

I have the following CRC 16 code. Is it possible to improve the performance of the code with unsafe constructs. My knowledge about pointer arithmetic is rather limited. public enum Crc16Mode : ...
6
votes
2answers
126 views

Handle static objects using custom adapter

I have read some articles discussing about why static is bad, some of them refering static as not-testable, non-mockable, has state (non-stateless) and everything else. However I have encountered ...
4
votes
3answers
172 views

Is this method doing too much?

I've got this method, and it's quite a big method. I look at it, and I feel... dirty. I feel that it's doing too much, and that there might be a better way to accomplish what I'm trying to. Here's the ...
0
votes
1answer
73 views

Dictionary Structure

I am brand new to dictionaries and coding and am hoping to get some suggestions on how I should structure my dictionary. I have a collector number which has meters connected to them. Each of the ...
4
votes
2answers
137 views

Is there a better way to consume an ASP.NET Web API call in an MVC controller?

In a new project I am creating for my work I am creating a fairly large ASP.NET Web API. The api will be in a separate visual studio solution that also contains all of my business logic and database ...
6
votes
2answers
112 views

Generic wrapper for equality and hash implementation: Is there a way I can make it more efficient?

I was writing an answer in another thread and came across this challenge. I'm trying to have a generic class so that I can delegate the routine (and tiring) Equals and GetHashCode implementation to it ...
0
votes
0answers
45 views

Improve my reactive code (ping/pong sample)

I'm starting with the reactive framework, how can I improve my logic? The way it is doing the code below, I can not add parameters in the composition, e.g.: Where, Syncronize, OnError.. How can I ...
5
votes
2answers
111 views

Better way to code download speed calcuation

I'm writing a program that downloads stuff from the internet. While the program is working fine, I want to get one critical part reviewed. I use System.Diagnostics.StopWatch object to measure the time ...
0
votes
3answers
86 views

Enumerating over a enum that defines months in the year

I have some code that allows me to enumerate over months in a year. This code is used both in a Web application as well as a standalone exe. Although it doesn't have to be efficient it is used a lot ...
3
votes
1answer
125 views

Homework assignment needs review

Will someone look over my code for an exercise I was assigned. The program runs, but my instructor is pretty tough at grading. Anything I can improve on? The exercise is as follows: Create a class ...
1
vote
0answers
47 views

Are there side-effects to having a generic Ninject factory?

Consider this class: using Ninject; using Ninject.Syntax; using Ninject.Parameters; namespace MyApp.Dependencies.Factories { public abstract class FactoryBase<T> where T : class { ...
5
votes
2answers
85 views

Extension methods for methods and properties that don't use non-public data

Generally speaking, I try and write my classes so they are highly cohesive. Sometimes I have accessors (this problem isn't limited to accessors) which derive their value from non-public data only, ...
0
votes
1answer
55 views

Format A TimeSpan With Years

I have a class with 2 date properties: FirstDay and LastDay. LastDay is nullable. I would like to generate a string in the format of "x year(s) y day(s)". If the total years are less than 1, I ...

1 2 3 4 5 27