Skip to main content
Filter by
Sorted by
Tagged with
574 votes
12 answers
383k views

It's clear that a search performance of the generic HashSet<T> class is higher than of the generic List<T> class. Just compare the hash-based key with the linear approach in the List<T&...
Michael Damatov's user avatar
274 votes
12 answers
249k views

Is there any way to check whether a file is locked without using a try/catch block? Right now, the only way I know of is to just open the file and catch any System.IO.IOException.
ricree's user avatar
  • 36.9k
266 votes
9 answers
239k views

In T-SQL you could have a query like: SELECT * FROM Users WHERE User_Rights IN ("Admin", "User", "Limited") How would you replicate that in a LINQ to Entities query? Is it even possible?
StevenMcD's user avatar
  • 17.6k
213 votes
6 answers
201k views

I am using a COM object (MODI) from within my .net application. The method I am calling throws a System.AccessViolationException, which is intercepted by Visual Studio. The odd thing is that I have ...
Jeremy's user avatar
  • 46.8k
635 votes
29 answers
525k views

I want to copy the entire contents of a directory from one location to another in C#. There doesn't appear to be a way to do this using System.IO classes without lots of recursion. There is a method ...
Keith's user avatar
  • 157k
295 votes
8 answers
81k views

In our project we're using TransactionScope's to ensure our data access layer performs it's actions in a transaction. We're aiming to not require the MSDTC service to be enabled on our end-user's ...
Yoopergeek's user avatar
  • 5,652
118 votes
14 answers
74k views

What is the best (and fastest) way to retrieve a random row using Linq to SQL when I have a condition, e.g. some field must be true?
Julien Poulin's user avatar
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
364 votes
19 answers
601k views

I've got a string in .NET which is actually a URL. I want an easy way to get the value from a particular parameter. Normally, I'd just use Request.Params["theThingIWant"], but this string ...
Beska's user avatar
  • 12.8k
238 votes
24 answers
229k views

I understand the difference between String and StringBuilder (StringBuilder being mutable) but is there a large performance difference between the two? The program I’m working on has a lot of case ...
Kuvo's user avatar
  • 2,411
968 votes
14 answers
810k views

I've searched around and haven't really found a clear answer as to when you'd want to use .First and when you'd want to use .FirstOrDefault with LINQ. When would you want to use .First? Only when you'...
Metro Smurf's user avatar
  • 38.5k
514 votes
32 answers
216k views

I'm building a class library that will have some public & private methods. I want to be able to unit test the private methods (mostly while developing, but also it could be useful for future ...
Eric Labashosky's user avatar
455 votes
22 answers
1.3m views

I am trying to read a *.csv-file. The *.csv-file consist of two columns separated by semicolon (";"). I am able to read the *.csv-file using StreamReader and able to separate each line by using the ...
Rushabh Shah's user avatar
  • 4,611
252 votes
9 answers
327k views

I googled around for information on how to hide one’s own console window. Amazingly, the only solutions I could find were hacky solutions that involved FindWindow() to find the console window by its ...
Timwi's user avatar
  • 66.8k
171 votes
4 answers
66k views

I know it is considered generally a bad idea to use fire-and-forget async void methods to start tasks, because there is no track of the pending task and it is tricky to handle exceptions which might ...
avo's user avatar
  • 10.9k
88 votes
8 answers
96k views

Should I use Named Pipes, or .NET Remoting to communicate with a running process on my machine?
mrbradleyt's user avatar
  • 2,356
497 votes
16 answers
79k views

I need to find a bottleneck and need to accurately as possible measure time. Is the following code snippet the best way to measure the performance? DateTime startTime = DateTime.Now; // Some ...
David Basarab's user avatar
447 votes
3 answers
420k views

There are two classes available in .NET: Task and Thread. What is the difference between those classes? When is it better to use Thread over Task (and vice-versa)?
Jacek's user avatar
  • 12.1k
386 votes
7 answers
268k views

Edit: This question looks like it might be the same problem, but has no responses... Edit: In test case 5 the task appears to be stuck in WaitingForActivation state. I've encountered some odd ...
Benjamin Fox's user avatar
  • 5,800
253 votes
40 answers
719k views

I am getting the following error when I post back a page from the client-side. I have JavaScript code that modifies an asp:ListBox on the client side. How do we fix this? Error details below: ...
140 votes
8 answers
93k views

I have the following problem: We have an application that loads modules (add ons). These modules might need entries in the app.config (e.g. WCF configuration). Because the modules are loaded ...
Daniel Hilgarth's user avatar
44 votes
3 answers
30k views

As I understand it there's a 2 GB limit on single instances in .NET. I haven't paid a lot of attention to that since I have mainly worked on 32 bit OS so far. On 32 but it is more or less an ...
Brian Rasmussen's user avatar
429 votes
7 answers
450k views

I'm using iTextSharp to read the text from a PDF file. However, there are times I cannot extract text, because the PDF file is only containing images. I download the same PDF files everyday, and I ...
broke's user avatar
  • 8,342
319 votes
20 answers
395k views

I have Googled a lot and found a lot of solutions, but none of them give me the correct week number for the 2012-12-31. Even the example on MSDN (link) fails. 2012-12-31 is Monday, therefore it ...
Amberlamps's user avatar
  • 40.7k
295 votes
5 answers
79k views

According to the documentation, the decimal.Round method uses a round-to-even algorithm which is not common for most applications. So I always end up writing a custom function to do the more natural ...
Darin Dimitrov's user avatar

1
3 4
5
6 7
1015