140,150 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?
948
votes
14
answers
612k
views
How to enable assembly bind failure logging (Fusion) in .NET
How do I enable assembly bind failure logging (Fusion) in .NET?
505
votes
5
answers
305k
views
Is there a conditional ternary operator in VB.NET?
In Perl (and other languages) a conditional ternary operator can be expressed like this:
my $foo = $bar == $buz ? $cat : $dog;
Is there a similar operator in VB.NET?
476
votes
16
answers
318k
views
When should I use a List vs a LinkedList
When is it better to use a List vs a LinkedList?
438
votes
47
answers
490k
views
Difference in months between two dates
How to calculate the difference in months between two dates in C#?
Is there is equivalent of VB's DateDiff() method in C#. I need to find difference in months between two dates that are years apart. ...
351
votes
10
answers
520k
views
How do I get my C# program to sleep for 50 milliseconds?
How do I get my C# program to sleep (pause execution) for 50 milliseconds?
328
votes
7
answers
24k
views
What is the purpose of a stack? Why do we need it?
So I am learning MSIL right now to learn to debug my C# .NET applications.
I've always wondered: what is the purpose of the stack?
Just to put my question in context:
Why is there a transfer from ...
314
votes
14
answers
299k
views
Is it possible to write to the console in colour in .NET?
Writing a small command line tool, it would be nice to output in different colours. Is this possible?
258
votes
8
answers
630k
views
HTML encoding issues - "Â" character showing up instead of " "
I've got a legacy app just starting to misbehave, for whatever reason I'm not sure. It generates a bunch of HTML that gets turned into PDF reports by ActivePDF.
The process works like this:
Pull an ...
241
votes
14
answers
418k
views
Check if a string contains an element from a list (of strings)
For the following block of code:
For I = 0 To listOfStrings.Count - 1
If myString.Contains(lstOfStrings.Item(I)) Then
Return True
End If
Next
Return False
The output is:
Case 1:
...
226
votes
25
answers
231k
views
Get the generated SQL statement from a SqlCommand object?
I have the following code:
Using cmd As SqlCommand = Connection.CreateCommand
cmd.CommandText = "UPDATE someTable SET Value = @Value"
cmd.CommandText &= " WHERE Id = @Id"
cmd....
223
votes
12
answers
174k
views
.Net Data structures: ArrayList, List, HashTable, Dictionary, SortedList, SortedDictionary -- Speed, memory, and when to use each? [closed]
.NET has a lot of complex data structures. Unfortunately, some of them are quite similar and I'm not always sure when to use one and when to use another. Most of my C# and VB books talk about them to ...
219
votes
7
answers
192k
views
What exceptions should be thrown for invalid or unexpected parameters in .NET?
What types of exceptions should be thrown for invalid or unexpected parameters in .NET? When would I choose one instead of another?
Follow-up:
Which exception would you use if you have a function ...
212
votes
17
answers
123k
views
Max or Default?
What is the best way to get the Max value from a LINQ query that may return no rows? If I just do
Dim x = (From y In context.MyTable _
Where y.MyField = value _
Select y.MyCounter)....
206
votes
5
answers
202k
views
How to write Unicode characters to the console?
I was wondering if it was possible, in a console application, to write characters like ℃ using .NET. When I try to write this character, the console outputs a question mark.
202
votes
6
answers
80k
views
Is there a VB.NET equivalent for C#'s '??' operator?
Is there a VB.NET equivalent for C#'s ?? operator?
194
votes
14
answers
150k
views
ObservableCollection Doesn't support AddRange method, so I get notified for each item added, besides what about INotifyCollectionChanging?
I want to be able to add a range and get updated for the entire bulk.
I also want to be able to cancel the action before it's done (i.e. collection changing besides the 'changed').
Related Q
Which ....
182
votes
12
answers
282k
views
What is the C# version of VB.NET's InputBox?
What is the C# version of VB.NET's InputBox?
176
votes
48
answers
205k
views
The name does not exist in the namespace error in XAML
Using VS2012 working on a VB.NET WPF application. I have a simple MusicPlayer tutorial app I am using to learn WPF. I am converting a C# version of the tutorial to VB.NET step by step.
It has 2 ...
173
votes
8
answers
165k
views
Classes vs. Modules in VB.NET
Is it considered an acceptable practice to use Modules instead of Classes with Shared member functions in VB.NET?
I tend to avoid Modules, because they feel like leftover remains from Visual Basic 6....
172
votes
17
answers
166k
views
Mixing C# & VB In The Same Project
Can you mix vb and c# files in the same project for a class library? Is there some setting that makes it possible?
I tried and none of the intellisense works quite right, although the background ...
166
votes
12
answers
76k
views
Is String.Format as efficient as StringBuilder
Suppose I have a stringbuilder in C# that does this:
StringBuilder sb = new StringBuilder();
string cat = "cat";
sb.Append("the ").Append(cat).(" in the hat");
string s = sb.ToString();
would that be ...
164
votes
13
answers
92k
views
.NET Configuration (app.config/web.config/settings.settings)
I have a .NET application which has different configuration files for Debug and Release builds. E.g. the debug app.config file points to a development SQL Server which has debugging enabled and the ...
162
votes
6
answers
104k
views
Linq to Sql: Multiple left outer joins
I'm having some trouble figuring out how to use more than one left outer join using LINQ to SQL. I understand how to use one left outer join. I'm using VB.NET. Below is my SQL syntax.
T-SQL
...
157
votes
10
answers
131k
views
Auto column width in EPPlus
How to make columns to be auto width when texts in columns are long?
I use this code
Worksheet.Column(colIndex).AutoFitColumn() 'on all columns'
Worksheet.cells.AutoFitColumns()
Worksheet.Column(...