Thanks for the copy and pasted code Chris. ;-) I used a similar
snippet and read the same statement regarding the enumeration...
Using the remote MSDN copy of what we have locally...
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/
cpref/html/frlrfsystemnethttpstatuscodeclasstopic.asp
To make the long story short I was not casting the StatusCode
property to an int. How would I know? Am I to understand that
all enums return an integer type?
Clinton,
Int32 is the default type for enums. You can specify any other
integral type (except System.Char) as the type for an enum.
Enums can be a little confusing. A fair amount of casting has to be
used when accessing an enum value. There's also one way to create an
enum, and another way to access its properties and methods.
Creating an enum is done via the enum keyword:
// Using the default System.Int32 (C# "int) type:
public enum Enum1 { Value1 = 1, Value2 = 2 }
// Using the System.Byte (C# "byte") type:
public enum Enum2 : byte { Value1 = 128, Value2 = 138 }
Enum instances can be accessed using the methods and
properties defined in the System.Enum class. The help entries for
this class have several examples.
// Note the curiosity regarding no requirement to use the
ToString( ) method
nor cast the same property to an int unless I would have somehow
known to
do so. These circumstantial uses of type are keeping me
confused.
The C# Language Reference, while dry at times, is invaluable in
learning all of the nuances and quirks of C#. Section 7.7.4 covers
the addition operator (+). For string addition where only one of the
operands is a string, the compiler will call the .ToString() method
of the non-string operand. You can see this in action by overriding
the .ToString() method of a simple class:
using System;
namespace ExampleNamespace
{
public class ToStringClass
{
// By default, ToString() returns the fully
// qualified name of its type. Comment out this
// ToString() method to see what would otherwise be printed
// by the code in the Main() method...
public override string ToString()
{
return "42";
}
}
public class ExampleClass
{
[STAThread]
public static void Main()
{
ToStringClass tsc = new ToStringClass();
string msg =
"The answer to life, the universe and " +
"everything is " + tsc;
Console.WriteLine(msg) ;
}
}
}
Hope this helps.
Chris.