6
votes
2answers
125 views

List<T> Any vs Count, which one is better for readability?

Resharper thinks I should change this while (dockPanel.Contents.Count() > 0) to the following: while (dockPanel.Contents.Any()) Without thinking twice about it, I switched to the any version ...
3
votes
1answer
87 views

Looking for advice on how to make my code better

I have to make project for school in C# which has to use database and web service. I have made program which starts web service and gets function from web service which is used for connecting to ...
2
votes
1answer
107 views

Is there a safer/ more readable way of using this code?

Is there a safer/ more readable way of using this code? I gotta translate this code into a better , safer and more readable sample of code and get my onclick to work.(its currently called from another ...
3
votes
3answers
55 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 ...
6
votes
2answers
141 views

Left hand search in string

the requirement for our search query is to look for all search words in the beginning of vehicle manufacturer, model and variant name. Case insensitive. The word being a string of characters separated ...
1
vote
2answers
134 views

Can I improve this code for readability and/or performance?

I have some data that logs kWh. I want to be able to collect the data and produce a bar chart (I'm using the Microsoft ASP.Net Chart control). I have written code that works, but it looks a little ...
5
votes
4answers
218 views

Should a piece of code only ever called once be a separate method?

I'm curious when a piece of code should be its own method or just left alone. This came up when I was creating a "work item" from the thread pool. When passing the argument to the "WaitCallback" ...
5
votes
2answers
241 views

How can I make this fast and more readable?

I made a simple library to help me doing A/B tests in a web app. The idea is simple: I have two or more page options (url) for a given page and every call to the library method should give me a url so ...
3
votes
5answers
176 views

how to improve readability of my code for a medium size program

I am writing a program for my trading application. Over the months the program has been growing steadily, and what is used to be a small program now i would call a medium size program (about ...
2
votes
2answers
595 views

Pinging application

I know this may be very time consuming for you as the answerer of this question, but I have recently been looking into C# and I decided that I would try to develop a pinging application, so that I ...
3
votes
2answers
180 views

Refactor to make intention clearer and testable

I'd like to improve the readability of the following code. The aim of this code is to apply formatting to row(s) in a WinForms DataGridView based on the Priority of an item, determined either by its ...
1
vote
0answers
317 views

asp.net controls to dump key/value pairs

I just wrote this code and am curious if it looks good and readable or if maybe it's over optimized (or other issues). Are there alternative (better) ways to factor out the common parts other than my ...
17
votes
13answers
5k views

Using return value vs out parameters

It's very popular to see codes like this : bool DoSomething([some arguments]); I mean you can't understand what's the result of this method by looking at its name.(actually it could be a void) ...
2
votes
2answers
551 views

using break in a while loop vs while condition readablitiy

I am refactoring my code to be more readable.Which version is more readable in your opinion and why ? var result = new ErrorHandlerResult(); while(exp!=null) { ...
2
votes
2answers
164 views

C# review requests

The following piece of code is used to re position controls on a form considering different options. Once you have multiple controls this becomes quite messy. I would appreciate your improvement ...
7
votes
5answers
500 views

Is `for b in {true, false}` an acceptable hack?

I'm trying to perform an action on just a few lines, once for true and false each. foreach (var b in new bool[] { true, false }) { var tmp = DoStuff (b); DoMoreStuff (tmp); ...
11
votes
7answers
910 views

Switch case statement refactoring

I have the following code with switch case statement: public string IrregularCouponLabel { get { switch ((ctrl.IrregularCouponFirst ? 10 : 0) + (ctrl.IrregularCouponLast ? 1 : 0)) ...
3
votes
1answer
394 views

Best way to make parser code more readable and efficient?

I am optimizing the variable parser for my programming language, and also trying to make it more readable and concise (precedence: readabl e& concise > efficient). What is the best way to improve ...
28
votes
7answers
2k views

Is this too fancy?

I just rewrote this: if (budgetRemaining != 0 || totalOpenInvoices != 0) { } Like this: if (new[] { budgetRemaining, totalOpenInvoices }.Any(c => c != 0)) { } If I had seen that before I ...
2
votes
9answers
364 views

Concise null checking vs readability

I've got a case where I need to call a couple of methods, checking if they return null, and return some property from the result of the second when neither returns null. I've thought of two ways to ...
2
votes
4answers
321 views

Using an extension method for a small helper task that (ab)uses the fact that the object is not dereferenced

I've recently got into an habit where I've used extension methods for giving things fluent-like properties - such as the below example or as another example entity.AssertNotNull() public static class ...
8
votes
6answers
2k views

Getting the miliseconds from now to the next midday

I need to get the total milliseconds to the next mid-day (12:00:00) to signal a timer that will run once a day. Assuming the application can be shut down and started anytime, is this code to get ...
8
votes
1answer
456 views

Review Request: House number parsing

I have 2 functions used for parsing a house number and I think these can be improved. Any suggestions? Thanks in: "45a - 47b" or "45a bis 47b" out: 45,a,47,b public static string[] ...