All Questions

1882
votes
33answers
841303 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?...
1063
votes
43answers
498786 views

How do I update the GUI from another thread in C#?

What is the simplest way to update a Label from another thread? I have a Form on thread1, and from that I'm starting another thread (thread2). While thread2 is processing some files I would like to u...
120
votes
3answers
82413 views

What is an IndexOutOfRangeException / ArgumentOutOfRangeException and how do I fix it?

I have some code and when it executes, it throws a IndexOutOfRangeException, saying, Index was outside the bounds of the array. What does this mean, and what can I do about it? Depending on cl...
1127
votes
16answers
144420 views

What is the best algorithm for an overridden System.Object.GetHashCode?

In .NET System.Object.GetHashCode method is used in a lot of places, throughout the .NET base class libraries. Especially when finding items in a collection fast or to determine equality. Is there a ...
1687
votes
37answers
646178 views

Deep cloning objects

I want to do something like: MyObject myObj = GetMyObj(); // Create and fill a new object MyObject newObj = myObj.Clone(); And then make changes to the new object that are not reflected in the orig...
1451
votes
40answers
864416 views

Create Excel (.XLS and .XLSX) file from C#

How can I create an Excel Spreadsheet with C# without requiring Excel to be installed on the machine that's running the code?
711
votes
21answers
439778 views

Sending email in .NET through Gmail

Instead of relying on my host to send 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 to d...
710
votes
21answers
462872 views

Deserialize JSON into C# dynamic object?

Is there a way to deserialize JSON content into a C# 4 dynamic type? It would be nice to skip creating a bunch of classes in order to use the DataContractJsonSerializer.
563
votes
23answers
559855 views

Encrypt and decrypt a string

Can someone give me the code to encrypt and decrypt a string in C#?
668
votes
10answers
335481 views

How do I force my .NET application to run as administrator?

Once my program is installed on a client machine, how do I force my program to run as an administrator on Windows 7?

Previous Next