Join us in building a kind, collaborative learning community via our updatedCode of Conduct.

Questions tagged [.net]

The .NET framework is a software framework designed mainly for the Microsoft Windows operating system. It includes an implementation of the Base Class Library, Common Language Runtime (commonly referred to as CLR), Common Type System (commonly referred to as CTS) and Dynamic Language Runtime. It ...

5378
votes
58answers
877k views

What is the difference between String and string in C#?

Example (note the case):string s="Hello world!";String s="Hello world!";What are the guidelines for the use of each? And what are the differences?
3123
votes
27answers
611k views

How do I enumerate an enum?

How can you enumerate an enum in C#?E.g. the following code does not compile:public enum Suit {Spades,Hearts,Clubs,Diamonds}public void EnumerateAllSuitsDemoMethod() {...
2076
votes
9answers
290k views

What are the correct version numbers for C#?

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 ...
1917
votes
38answers
1.1m views

How do I get a consistent byte representation of strings in C# without manually specifying an encoding?

How do I convert a string to a byte[] in .NET (C#) without manually specifying a specific encoding?I'm going to encrypt the string. I can encrypt it without converting, but I'd still like to know ...
1878
votes
33answers
981k 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?
1833
votes
39answers
684k views

Deep cloning objects

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

Difference between decimal, float and double in .NET?

What is the difference between decimal, float and double in .NET?When would someone use one of these?
1744
votes
64answers
476k views

How do I calculate someone's age in C#?

Given a DateTime representing a person's birthday, how do I calculate their age in years?
1743
votes
9answers
160k views

Should 'using' directives be inside or outside the namespace?

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 ...
1715
votes
26answers
425k views

Catch multiple exceptions at once?

It is discouraged to simply catch System.Exception. Instead, only the "known" exceptions should be caught.Now, this sometimes leads to unneccessary repetitive code, for example:try{WebId=...
1573
votes
40answers
919k 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?
1384
votes
18answers
273k views

Proper use of the IDisposable interface

I know from reading the MSDN documentation that the "primary" use of the IDisposable interface is to clean up unmanaged resources.To me, "unmanaged" means things like database connections, sockets, ...
1343
votes
5answers
91k views

Try-catch speeding up my code?

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....
1223
votes
17answers
161k 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 ...
1206
votes
18answers
476k views

Why is Dictionary preferred over Hashtable?

In most programming languages, dictionaries are preferred over hashtables.What are the reasons behind that?

153050per page
angop.ao, elkhabar.com, noa.al, afghanpaper.com, bbc.com, time.com, cdc.gov, nih.gov, xnxx.com, github.com,