Skip to main content
Filter by
Sorted by
Tagged with
7595 votes
67 answers
1.4m views

What are the differences between these two, and which one should I use? string s = "Hello world!"; String s = "Hello world!";
2923 votes
13 answers
441k views

What are the correct version numbers for C#? What came out when? Why can't I find any answers about C# 3.5? This question is primarily to aid those who are searching for an answer using an incorrect ...
2631 votes
29 answers
909k views

It is discouraged to catch System.Exception errors. Instead, only the "known" exceptions should be caught. This sometimes leads to unnecessary repetitive code, for example: try { WebId = ...
Michael Stum's user avatar
2440 votes
15 answers
293k views

I have been running StyleCop over some C# code, and it keeps reporting that my using directives should be inside the namespace. Is there a technical reason for putting the using directives inside ...
benPearce's user avatar
  • 38.5k
2271 votes
76 answers
860k views

Given a DateTime representing a person's birthday, how do I calculate their age in years?
2136 votes
117 answers
1.9m views

A C# desktop application (on the Visual Studio Express edition) worked, but then it didn't work 5 seconds later. I tried the following: Ensure debug configuration, debug flag, and full debug ...
1881 votes
10 answers
1.5m views

If I inherit from a base class and want to pass something from the constructor of the inherited class to the constructor of the base class, how do I do that? For example, if I inherit from the ...
lomaxx's user avatar
  • 116k
1786 votes
8 answers
1.0m views

public enum Foos { A, B, C } Is there a way to loop through the possible values of Foos? Basically? foreach(Foo in Foos)
divinci's user avatar
  • 23.3k
1733 votes
30 answers
542k views

What is the difference between const and readonly in C#? When would you use one over the other?
readonly's user avatar
  • 358k
1637 votes
6 answers
122k views

I wrote some code for testing the impact of try-catch, but seeing some surprising results. static void Main(string[] args) { Thread.CurrentThread.Priority = ThreadPriority.Highest; Process....
Eren Ersönmez's user avatar
1583 votes
19 answers
630k views

In most programming languages, dictionaries are preferred over hashtables. What are the reasons behind that?
Nakul Chaudhary's user avatar
1500 votes
17 answers
2.6m views

How can I make an HTTP POST request and send data in the body?
Hooch's user avatar
  • 29.8k
1355 votes
61 answers
889k views

I am trying to run an ASP.NET MVC (model-view-controller) project retrieved from TFS (Team Foundation Server) source control. I have added all assembly references and I am able to build and compile ...
Eyad's user avatar
  • 14.4k
1341 votes
39 answers
1.3m views

How can I generate a random 8 character alphanumeric string in C#?
KingNestor's user avatar
  • 68.4k
1288 votes
15 answers
2.3m views

I have classes like these: class MyDate { int year, month, day; } class Lad { string firstName; string lastName; MyDate dateOfBirth; } And I would like to turn a Lad object into a ...
Hui's user avatar
  • 14.6k
1199 votes
15 answers
817k views

How can I do group by multiple columns in LINQ? Something similar to this in SQL: SELECT * FROM <TableName> GROUP BY <Column1>,<Column2> How can I convert this to LINQ: ...
Sreedhar's user avatar
  • 30.2k
1186 votes
16 answers
1.6m views

I have a byte[] array that is loaded from a file that I happen to known contains UTF-8. In some debugging code, I need to convert it to a string. Is there a one-liner that will do this? Under the ...
BCS's user avatar
  • 79.2k
1154 votes
22 answers
1.2m views

I'm trying to perform a LINQ query on a DataTable object and bizarrely I am finding that performing such queries on DataTables is not straightforward. For example: var results = from myRow in ...
Calanus's user avatar
  • 26.4k
1089 votes
13 answers
646k views

In ASP.NET MVC, what is the difference between: Html.Partial and Html.RenderPartial Html.Action and Html.RenderAction
Ghooti Farangi's user avatar
1067 votes
1 answer
315k views

How do I display a literal curly brace character when using the String.Format method? Example: sb.AppendLine(String.Format("public {0} {1} { get; private set; }", prop.Type, prop.Name)); I would ...
PhilB's user avatar
  • 11.9k
1028 votes
14 answers
247k views

In Visual Studio, there are at least three different types of class libraries you can create: Class Library (.NET Framework) Class Library (.NET Standard) Class Library (.NET Core) While the first ...
Gigi's user avatar
  • 29.7k
1006 votes
21 answers
747k views

I'm writing a program in C# that needs to repeatedly access 1 image file. Most of the time it works, but if my computer's running fast, it will try to access the file before it's been saved back to ...
Dawsy's user avatar
  • 10.6k
989 votes
17 answers
785k views

I need to split a string into newlines in .NET and the only way I know of to split strings is with the Split method. However that will not allow me to (easily) split on a newline, so what is the best ...
RCIX's user avatar
  • 39.7k
971 votes
28 answers
1.4m views

I'm working on a C# class library that needs to be able to read settings from the web.config or app.config file (depending on whether the DLL is referenced from an ASP.NET web application or a Windows ...
Russ Clark's user avatar
  • 13.5k
971 votes
27 answers
680k views

Instead of relying on my host to send an email, I was thinking of sending the email messages using my Gmail account. The emails are personalized emails to the bands I play on my show. Is it possible ...
Mike Wills's user avatar
  • 21.3k

1
2 3 4 5
6816