Skip to main content
Filter by
Sorted by
Tagged with
538 votes
8 answers
528k views

What is the proper way to turn a char[] into a string? The ToString() method from an array of characters doesn't do the trick.
BuddyJoe's user avatar
  • 71.4k
527 votes
9 answers
384k views

What is the best data type to use for money in C#?
NotDan's user avatar
  • 32.3k
517 votes
14 answers
196k views

What is the difference between Math.Floor() and Math.Truncate() in .NET?
Anonymous User's user avatar
511 votes
11 answers
241k views

What's the quickest and easiest way to get the Min (or Max) value between two dates? Is there an equivalent to Math.Min (& Math.Max) for dates? I want to do something like: if (Math.Min(Date1, ...
hawbsl's user avatar
  • 16.2k
511 votes
12 answers
492k views

What is the difference between ArrayList and List<> in C#? Is it only that List<> has a type while ArrayList doesn't?
scatman's user avatar
  • 14.6k
503 votes
25 answers
417k views

I am processing a TreeView of directories and files. A user can select either a file or a directory and then do something with it. This requires me to have a method which performs different actions ...
SnAzBaZ's user avatar
  • 6,599
500 votes
7 answers
259k views

What is the difference between the internal and private access modifiers in C#?
Jim Fell's user avatar
  • 14.4k
497 votes
14 answers
954k views

There are a lot of different ways to read and write files (text files, not binary) in C#. I just need something that is easy and uses the least amount of code, because I am going to be working with ...
ApprenticeHacker's user avatar
496 votes
11 answers
464k views

C# 2008 SP1 I am using the code below: dt.ReadXml("%AppData%\\DateLinks.xml"); However, I am getting an exception that points to the location of where my application is running from: Could not ...
ant2009's user avatar
  • 22.7k
494 votes
15 answers
350k views

In C#, the result of Math.Round(2.5) is 2. It is supposed to be 3, isn't it? Why is it 2 instead in C#?
jeffu's user avatar
  • 5,067
492 votes
17 answers
273k views

I'm trying to create a new object of type T via its constructor when adding to the list. I'm getting a compile error: The error message is: 'T': cannot provide arguments when creating an instance ...
LB.'s user avatar
  • 14.1k
490 votes
7 answers
509k views

I want to create a varchar column in SQL that should contain N'guid' while guid is a generated GUID by .NET (Guid.NewGuid) - class System.Guid. What is the length of the varchar I should expect from ...
Shimmy Weitzhandler's user avatar
488 votes
20 answers
217k views

Inspired by another question asking about the missing Zip function: Why is there no ForEach extension method on the IEnumerable interface? Or anywhere? The only class that gets a ForEach method is ...
Cameron MacFarland's user avatar
484 votes
21 answers
324k views

I'm trying to insert a certain number of indentations before a string based on an items depth and I'm wondering if there is a way to return a string repeated X times. Example: string indent = "---"; ...
Abe Miessler's user avatar
  • 85.6k
481 votes
7 answers
599k views

Given a datasource like that: var c = new Car[] { new Car{ Color="Blue", Price=28000}, new Car{ Color="Red", Price=54000}, new Car{ Color="Pink", Price=9999}, // .. }; How can I find the ...
codymanix's user avatar
  • 29.7k
478 votes
150 answers
135k views

Let's make a list of answers where you post your excellent and favorite extension methods. The requirement is that the full code must be posted and a example and an explanation on how to use it. ...
476 votes
16 answers
318k views

When is it better to use a List vs a LinkedList?
Jonathan Allen's user avatar
473 votes
32 answers
859k views

I have a requirement to find and extract a number contained within a string. For example, from these strings: string test = "1 test" string test1 = " 1 test" string test2 = "test 99" How can I do ...
van's user avatar
  • 9,449
465 votes
18 answers
1.6m views

This is the code I have so far: public class Class1 { private const string URL = "https://sub.domain.com/objects.json?api_key=123"; private const string DATA = @"...
NullVoxPopuli's user avatar
463 votes
3 answers
402k views

Currently I am using following function to get the temporary folder path for current user: string tempPath = System.IO.Path.GetTempPath(); On some machines it gives me temp folder path of current ...
Anoop's user avatar
  • 5,396
458 votes
6 answers
233k views

Just wondering what the difference between BeginInvoke() and Invoke() are? Mainly what each one would be used for. EDIT: What is the difference between creating a threading object and calling ...
Nathan W's user avatar
  • 55.7k
453 votes
41 answers
337k views

In C#/VB.NET/.NET, which loop runs faster, for or foreach? Ever since I read that a for loop works faster than a foreach loop a long time ago I assumed it stood true for all collections, generic ...
450 votes
5 answers
55k views

I was looking for an efficient approach for calculating ab (say a = 2 and b = 50). To start things up, I decided to take a look at the implementation of Math.Pow() function. But in .NET Reflector, all ...
Pawan Mishra's user avatar
  • 7,278
448 votes
20 answers
420k views

I've been wrestling with this for a while and can't quite figure out what's happening. I have a Card entity which contains Sides (usually 2) - and both Cards and Sides have a Stage. I'm using EF ...
SB2055's user avatar
  • 13k
447 votes
18 answers
575k views

To create a new event handler on a control you can do this c.Click += new EventHandler(mainFormButton_Click); or this c.Click += mainFormButton_Click; and to remove an event handler you can do this ...
Carrick's user avatar
  • 4,563