tagged [coding-style]

Commenting out whole file

Commenting out whole file Sometimes, I need to comment out a whole file. Normally, I'd just wrap the class in `/* */`, but that doesn't work if there's already existing comments inside the class: Is t...

25 Jan at 10:56

When do you use the "this" keyword?

When do you use the "this" keyword? I was curious about how other people use the keyword. I tend to use it in constructors, but I may also use it throughout the class in other methods. Some examples: ...

12 Oct at 05:12

How do you test your Request.QueryString[] variables?

How do you test your Request.QueryString[] variables? I frequently make use of `Request.QueryString[]` variables. In my `Page_load` I often do things like: ``` int id = -1; if (Request.QueryString...

Is there a standard way to organize methods within a class?

Is there a standard way to organize methods within a class? There seem to be many different ways of organizing methods in a class. I could group methods by access, and order them alphabetically. I cou...

28 Jan at 16:35

How can I set multiple CSS styles in JavaScript?

How can I set multiple CSS styles in JavaScript? I have the following JavaScript variables: I know that I can set them to my element iteratively like this: Is it possible to set them all together at o...

24 Aug at 11:41

When to use Properties and Methods?

When to use Properties and Methods? I'm new to the .NET world having come from C++ and I'm trying to better understand properties. I noticed in the .NET framework Microsoft uses properties all over th...

20 Apr at 07:13

Replacing if(x) Foreach() with Foreach.Where(x)

Replacing if(x) Foreach() with Foreach.Where(x) Probably a stupid question but I have a lot of: constructs in some code Is replacing it with insane? It is probably less readable, but will the compiler...

8 Sep at 15:3

Get correct indentation in Resharper for object and array initializers

Get correct indentation in Resharper for object and array initializers Right now resharper formats our code like this: but I want it to look like this: ``` private readonly List f

Best way to check for nullable bool in a condition expression (if ...)

Best way to check for nullable bool in a condition expression (if ...) I was wondering what was the most clean and understandable syntax for doing condition checks on nullable bools. Is the following ...

20 Apr at 09:26

ReSharper C# naming style for private methods and properties

ReSharper C# naming style for private methods and properties I like to make the first letter of private methods, properties and events lowercase and the first letter of public methods, properties and ...

Why does one often see "null != variable" instead of "variable != null" in C#?

Why does one often see "null != variable" instead of "variable != null" in C#? In c#, is there any difference in the excecution speed for the order in which you state the condition? Since recently, I ...

7 Nov at 08:57

Setting top and left CSS attributes

Setting top and left CSS attributes For some reason I'm unable to set the "top" and "left" CSS attributes using the following JavaScript. Using Firebug I can see that the `div` gets the `position` set...

15 Feb at 04:2

methods in constructors, bad?

methods in constructors, bad? I have a windows form, and I have a class that checks a text file to make sure it has certain aspect. Now I have methods in a constructor and it seems a little weird. Sho...

13 Jan at 19:6

How can I get VisualStudio 2010 with ReSharper to preserve my spaces between '<%:', content, and '%>'?

How can I get VisualStudio 2010 with ReSharper to preserve my spaces between ''? I have Visual Studio 2010 and ReSharper installed and after looking for about an hour, I can't find this formatting set...

Why should I use var instead of a type?

Why should I use var instead of a type? > [ReSharper and var](https://stackoverflow.com/questions/737835/resharper-and-var) After I have installed ReSharper it demands(by warnings) that I use var wh...

23 May at 11:47

How to generically format a boolean to a Yes/No string?

How to generically format a boolean to a Yes/No string? I would like to display Yes/No in different languages according to some boolean variable. Is there a generic way to format it according to the l...

Using true and false as the expressions in a conditional operation

Using true and false as the expressions in a conditional operation I'm maintaining some code and have found the following pattern a lot: instead of this: Is there any reason anyone would do this? Does...

Lance Hunt's C# Coding Standards - enum confusion

Lance Hunt's C# Coding Standards - enum confusion My team has recently started using [Lance Hunt's C# Coding Standards](http://weblogs.asp.net/lhunt/pages/CSharp-Coding-Standards-document.aspx) docume...

27 Feb at 11:17

Control Flow via Return vs. If/Else

Control Flow via Return vs. If/Else Which one is better (implicit control flow via or control flow via ) -- see below. Please explain what you see as advantage/disadvantage to either one. I like optio...

20 Jul at 23:12

Simple way to create matrix of random numbers

Simple way to create matrix of random numbers I am trying to create a matrix of random numbers, but my solution is too long and looks ugly this looks ok, but in my implementation it is which is extrem...

30 Apr at 14:51

C# coding standards for private member variables

C# coding standards for private member variables I saw two common approaches for coding standards for private member variables: and I believe the latter is coming from C++. Also, many people specify t...

7 Mar at 15:50

When to use properties instead of functions

When to use properties instead of functions This is probably a matter of personal preference, but when do you use properties instead of functions in your code For instance to get an error log I could ...

9 Nov at 09:0

Is it ever okay to catch an exception and do nothing?

Is it ever okay to catch an exception and do nothing? From my experience, I generally wouldn't do this. But if I had a piece of functionality that say, uses a 3rd party COM assembly which occasionally...

28 Apr at 01:52

cleanest way to skip a foreach if array is empty

cleanest way to skip a foreach if array is empty Not a major problem but I was wondering if there is a cleaner way to do this. It would be good to avoid nesting my code with an unnecessary if statemen...

10 Aug at 06:23

Does anyone still use [goto] in C# and if so why?

Does anyone still use [goto] in C# and if so why? I was wondering whether anyone still uses the "goto" keyword syntax in C# and what possible reasons there are for doing so. I tend to view any stateme...

1 Jul at 12:10