What is good syntax for instanating virtual types?

J

jsh02_nova

Is this 'good' code to debug?

//Create separate Type library
namespace Common
{
public sealed class Statuses
{
internal Statuses(){}
public sealed class Good
{
public const string Ok = "Ok";
}
public sealed class Bad
{
public const string NotOk = "NotOk";
}
}
}
// end

// Create simple console app to use library
using Common;
namespace ConsoleApplication1
{
class Class1
{
[STAThread]
static void Main(string[] args)
{
string tmp = "Ok";
bool isOk = String.Compare(tmp, Statuses.Good.Ok) == 0;
Console.WriteLine(isOk.ToString());
}
}
}
 
D

Duggi

I do not know what you are targetting!!

However what ever the code you wrote is not good!! Try refactoring it
to an enum

namespace ConsoleApplication1
{
public enum Statuses
{
Ok, NotOk
}

class Class1
{
[STAThread]
static void Main(string[] args)
{
string tmp = "Ok";
bool isOk = String.Compare(tmp, Statuses.Ok.ToString())
== 0;
Console.WriteLine(isOk.ToString());
}
}


-Cnu
 
J

jsh02_nova

The exercise was try to refactor multiple 'hard coded' string comparisons
into nested abstract types with public readonly string fields, using .Net
v1.1. These 'abstract' types would be used throughout the solution. It was
discovered that the VS 2003 IDE couldn’t 'debug' these nested types, but it
could be seen that their instances were being created by the CLR. So, the
String.Compare method was working but the VS 2003 IDE wouldn’t hold these
nested ‘sealed’ types in scope so that the types could be 'watched' in the
debugger.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top