May 2004 - Posts

How do I cast a string to an int, float, double, etc?
30 May 04 12:08 PM
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 use Read More...
Postedby CSharpFAQ | 11 Comments    
How are return values from a delegate handled?
27 May 04 03:50 PM
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: In this situation, Read More...
Postedby CSharpFAQ | 4 Comments    
Why don't nullable relational operators return bool? instead of bool?
25 May 04 11:51 AM
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 of i == Read More...
Postedby CSharpFAQ | 8 Comments    
Filed under:
Why can't I use the same variable as an inner loop does?
18 May 04 02:59 PM
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 on the “int i = 0;” part of the code. Read More...
Postedby CSharpFAQ | 8 Comments    
How do I write a method that accepts a variable number of parameters?
13 May 04 03:44 PM
Q: How do I write a method that accepts a variable number of parameters? A: Languages like C and C++ have always offered some means for using and creating functions capable to accept a variable number of parameters. The most widely known example of a Read More...
Postedby CSharpFAQ | 6 Comments    
Why doesn't C# support static method variables?
11 May 04 09:41 PM
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 to get Read More...
Postedby CSharpFAQ | 6 Comments    
Why must attribute properties be read/write in C#?
11 May 04 09:16 PM
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 MyAttribute(string Read More...
Postedby CSharpFAQ | 5 Comments    
Why do I get the error "Object reference not set to an instance of an object"?
06 May 04 09:01 PM
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 instantiated Read More...
Postedby CSharpFAQ | 10 Comments    

This Blog

Syndication

Page view tracker