50,724 questions
1866
votes
26
answers
2.5m
views
What is a NullReferenceException, and how do I fix it?
I have some code and when it executes, it throws a NullReferenceException, saying:
Object reference not set to an instance of an object.
What does this mean, and what can I do to fix this error?
1607
votes
47
answers
859k
views
How do I update the GUI from another thread?
Which is the simplest way to update a Label from another Thread?
I have a Form running on thread1, and from that I'm starting another thread (thread2).
While thread2 is processing some files I would ...
1693
votes
25
answers
308k
views
What is the best algorithm for overriding GetHashCode?
In .NET, the GetHashCode method is used in a lot of places throughout the .NET base class libraries. Implementing it properly is especially important to find items quickly in a collection or when ...
1204
votes
30
answers
1.2m
views
Deserialize JSON into C# dynamic object? [duplicate]
Is there a way to deserialize JSON content into a C# dynamic type? It would be nice to skip creating a bunch of classes in order to use the DataContractJsonSerializer.
2191
votes
49
answers
1.4m
views
How do I create an Excel (.XLS and .XLSX) file in C# without installing Microsoft Office?
How can I create an Excel spreadsheet with C# without requiring Excel to be installed on the machine that's running the code?
1006
votes
21
answers
747k
views
Is there a way to check if a file is in use?
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 ...
1424
votes
26
answers
1.3m
views
How and when to use ‘async’ and ‘await’
From my understanding one of the main things that async and await do is to make code easy to write and read - but is using them equal to spawning background threads to perform long duration logic?
I'...
1500
votes
17
answers
2.6m
views
Send HTTP POST request in .NET
How can I make an HTTP POST request and send data in the body?
756
votes
29
answers
845k
views
Encrypt and decrypt a string in C#? [closed]
How can I encrypt and decrypt a string in C#?
21
votes
2
answers
43k
views
MSI vs nuget packages: which are is better for continuous delivery?
Let's discuss following topic. There is application which currently is being deployed with good to know xcopy method.This approach makes difficult to manage dependencies, file updates etc. There is ...
408
votes
10
answers
83k
views
Why use async and return await, when you can return Task<T> directly?
Is there any scenario where writing method like this:
public async Task<SomeResult> DoSomethingAsync()
{
// Some synchronous code might or might not be here... //
return await ...
117
votes
17
answers
118k
views
What is the difference between a reference type and value type in c#?
Some guy asked me this question couple of months ago and I couldn't explain it in detail. What is the difference between a reference type and a value type in C#?
I know that value types are int, bool,...
203
votes
2
answers
67k
views
Why is an unreferenced object not finalized immediately after a call to `GC.Collect`?
Consider the below code:
public class Class1
{
public static int c;
~Class1()
{
c++;
}
}
public class Class2
{
public static void Main()
{
{
var c1=...
373
votes
30
answers
347k
views
What Are Some Good .NET Profilers?
What profilers have you used when working with .net programs, and which would you particularly recommend?
7595
votes
67
answers
1.4m
views
What is the difference between String and string in C#?
What are the differences between these two, and which one should I use?
string s = "Hello world!";
String s = "Hello world!";
872
votes
24
answers
872k
views
How to read embedded resource text file
How do I read an embedded resource (text file) using StreamReader and return it as a string? My current script uses a Windows form and textbox that allows the user to find and replace text in a text ...
849
votes
30
answers
2.2m
views
How can I convert String to Int?
I have a TextBoxD1.Text and I want to convert it to an int to store it in a database.
How can I do this?
567
votes
25
answers
339k
views
How do I remove diacritics (accents) from a string in .NET?
I'm trying to convert some strings that are in French Canadian and basically, I'd like to be able to take out the French accent marks in the letters while keeping the letter. (E.g. convert é to e, so ...
243
votes
22
answers
428k
views
MVVM: Tutorial from start to finish?
I'm a C#/Windows Forms programmer with more than 5 years experience. I've been investigating WPF using the MVVM (Model-View-ViewModel) design pattern. I have searched the Internet for tutorials. I ...
58
votes
3
answers
55k
views
What do Option Strict and Option Explicit do?
I saw this post:
Typos… Just use option strict and explicit please.. during one software development project, which I was on as a consultant, they were getting ridiculous amounts of errors ...
736
votes
20
answers
472k
views
C# difference between == and Equals()
I have a condition in a silverlight application that compares 2 strings, for some reason when I use == it returns false while .Equals() returns true.
Here is the code:
if (((ListBoxItem)lstBaseMenu....
594
votes
18
answers
351k
views
Can't specify the 'async' modifier on the 'Main' method of a console app
I am new to asynchronous programming with the async modifier. I am trying to figure out how to make sure that my Main method of a console application actually runs asynchronously.
class Program
{
...
731
votes
18
answers
532k
views
Embedding DLLs in a compiled executable
Is it possible to embed a pre-existing DLL into a compiled C# executable (so that you only have one file to distribute)? If it is possible, how would one go about doing it?
Normally, I'm cool with ...
13
votes
2
answers
20k
views
Why saving changes to a database fails?
I have following C# code in a console application.
Whenever I debug the application and run the query1 (which inserts a new value into the database) and then run query2 (which displays all the ...
46
votes
2
answers
22k
views
Clean up Excel Interop Objects with IDisposable
In my company the common way to release Excel Interop Objects is to use IDisposable the following way:
Public Sub Dispose() Implements IDisposable.Dispose
If Not bolDisposed Then
Finalize(...