Questions tagged [.net]
Do NOT use for questions about .NET Core - use [.net-core] instead. 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 supports many programming languages, including C#, VB.NET, F# and C++/CLI.
339,506
questions
7555
votes
68
answers
1.3m
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!";
4394
votes
35
answers
1.0m
views
How to 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()
{
...
2902
votes
13
answers
431k
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 ...
2647
votes
59
answers
1.0m
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 ...
2586
votes
29
answers
861k
views
Catch multiple exceptions at once?
It is discouraged to catch System.Exception errors. Instead, only the "known" exceptions should be caught.
This sometimes leads to unnecessary repetitive code, for example:
try
{
WebId = ...
2459
votes
18
answers
1.3m
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?
2413
votes
15
answers
284k
views
Should 'using' directives be inside or outside the namespace in C#?
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 ...
2367
votes
41
answers
1.2m
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 ...
2256
votes
75
answers
836k
views
How do I calculate someone's age based on a DateTime type birthday?
Given a DateTime representing a person's birthday, how do I calculate their age in years?
2174
votes
48
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?
2111
votes
114
answers
1.8m
views
How do I remedy "The breakpoint will not currently be hit. No symbols have been loaded for this document." warning?
A C# desktop application (on the Visual Studio Express edition) worked, but then it didn't work 5 seconds later.
I tried the following:
Ensure debug configuration, debug flag, and full debug ...
1897
votes
20
answers
435k
views
Proper use of the IDisposable interface
I know from reading Microsoft documentation that the "primary" use of the IDisposable interface is to clean up unmanaged resources.
To me, "unmanaged" means things like database ...
1867
votes
26
answers
2.3m
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?
1859
votes
10
answers
1.4m
views
Calling the base constructor in C#
If I inherit from a base class and want to pass something from the constructor of the inherited class to the constructor of the base class, how do I do that?
For example, if I inherit from the ...
1763
votes
8
answers
993k
views
How to loop through all enum values in C#? [duplicate]
This question already has an answer here:
How do I enumerate an enum in C#? 26 answers
public enum Foos
{
A,
B,
C
}
Is there a way to loop through the possible values of Foos?
...