Sign In
C# Frequently Asked Questions
The C# team posts answers to common questions and describes new language features
Translate This Page
Translate this page
Powered by
Microsoft® Translator
Options
Email Blog Author
RSS for posts
Atom
RSS for comments
OK
Search
Advanced search options...
Search In:
Everything
Blogs
Forums
People
Groups
Places
Pages
Date range:
All Time
Last Year
Last 6 Months
Last 3 Months
Last Month
Last Week
Last Two Days
Tags
.NET Framework
.NET Framework 4
async
asynchronous programming
await
C#
C# 3.0
C# 4.0
C# compiler
C#/VB.NET Equivalents
DLR
dynamic language runtime
expression trees
IDE
parallel-processing
parallel-programming
reflection
roslyn
Task Parallel Library
Tips
TPL
Visual Studio
Visual Studio 2010
Visual Studio Async CTP
WPF
Archive
Archives
April 2012
(1)
February 2012
(3)
January 2012
(2)
December 2011
(1)
November 2011
(3)
October 2011
(1)
August 2011
(2)
April 2011
(1)
March 2011
(1)
February 2011
(1)
November 2010
(1)
October 2010
(1)
September 2010
(1)
August 2010
(1)
July 2010
(2)
June 2010
(2)
May 2010
(1)
April 2010
(2)
March 2010
(1)
February 2010
(1)
January 2010
(2)
November 2009
(1)
October 2009
(2)
September 2009
(1)
March 2009
(1)
January 2009
(1)
October 2006
(2)
March 2006
(3)
February 2005
(1)
December 2004
(4)
November 2004
(1)
October 2004
(15)
August 2004
(3)
July 2004
(3)
June 2004
(1)
May 2004
(8)
April 2004
(4)
March 2004
(36)
May, 2004
MSDN Blogs
>
C# Frequently Asked Questions
>
May, 2004
Posts
Subscribe via RSS
Sort by:
Most Recent
|
Most Views
|
Most Comments
Excerpt View
|
Full Post View
C# Frequently Asked Questions
How do I cast a string to an int, float, double, etc?
Posted
over 8 years ago
by
CSharpFAQ
14
Comments
You can use the Convert class or the Parse method of the built-in type you are casting to. i.e. string myStr = "123"; int myParsedInt = Int32.Parse(myStr); int myConvertedInt = Convert.ToInt32(myStr); This example uses the int type, but you can also...
C# Frequently Asked Questions
How are return values from a delegate handled?
Posted
over 8 years ago
by
CSharpFAQ
4
Comments
Q: How are multiple return values from a delegate handled? In C#, it's possible to write a delegate such as: delegate double GetResult(params double p); If there is more than one method on this delegate, there are multiple return values. A...
C# Frequently Asked Questions
Why don't nullable relational operators return bool? instead of bool?
Posted
over 8 years ago
by
CSharpFAQ
9
Comments
Q: Why don't nullable relational operators return “bool?” instead of “bool“? Nullable types are a new feature of C# 2.0 . When dealing with nullable types, if you write the following: int? i = 15; int? j = 16; the type...
C# Frequently Asked Questions
Why can't I use the same variable as an inner loop does?
Posted
over 8 years ago
by
CSharpFAQ
9
Comments
Q: Why can't I do the following: namespace Bug { class Class1 { [ STAThread ] static void Main ( string [] args ) { for ( int i = 0; i < 100; i ++ ) { } int i = 0; } } } the compiler gives me an error...
C# Frequently Asked Questions
How do I write a method that accepts a variable number of parameters?
Posted
over 8 years ago
by
CSharpFAQ
10
Comments
Update: Named and optional (default) parameters are available starting from C# 4.0. For more information, see Named and Optional Arguments (C# Programming Guide) . Q: How do I write a method that accepts a variable number of parameters? ...
C# Frequently Asked Questions
Why doesn't C# support static method variables?
Posted
over 8 years ago
by
CSharpFAQ
10
Comments
Q: In C++, it's possible to write a static method variable, and have a variable that can only be accessed from inside the method. C# doesn't provide this feature. Why? A: There are two reasons C# doesn't have this feature. First, it is possible...
C# Frequently Asked Questions
Why must attribute properties be read/write in C#?
Posted
over 8 years ago
by
CSharpFAQ
5
Comments
Q: Why must attribute properties be read/write in C#? In the C# language, when you define an attribute class, you can define both constructor arguments and properties. For example: class MyAttribute: Attribute { string name; int number; public...
C# Frequently Asked Questions
Why do I get the error "Object reference not set to an instance of an object"?
Posted
over 8 years ago
by
CSharpFAQ
16
Comments
The code is trying to access a member of a reference type variable that is set to null . Given the following class, let's examine some code that could be in the Main method: using System; class Foo { static void Main() { // foo has not been...
Page 1 of 1 (8 items)