473,320 Members | 2,071 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

What is good syntax for instanating virtual types?

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());
}
}
}
Jun 27 '08 #1
4 1194
On Thu, 29 May 2008 16:25:00 -0700, jsh02_nova
<js*******@discussions.microsoft.comwrote:
Is this 'good' code to debug?
I don't even understand the question. Looking just at your subject, the
answer is "there's no such thing as a 'virtual type'". Looking at the
code, I'd have to say "no, that's not good code". For one, I don't see
the point of the nested classes "Ok" and "NotOk". They seem like a
pointless redundancy to me.

If you can be more clear about your question -- what is it that you think
a "virtual type" is, and what specific goal do you have in mind that
you're trying to address -- maybe a better answer would be forthcoming. :)

Pete
Jun 27 '08 #2
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

On May 30, 4:25*am, jsh02_nova <jsh02n...@discussions.microsoft.com>
wrote:
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());
* * * * * }
* * *}

}- Hide quoted text -

- Show quoted text -
Jun 27 '08 #3
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.
Jun 27 '08 #4
On Fri, 30 May 2008 15:58:00 -0700, jsh02_nova
<js*******@discussions.microsoft.comwrote:
The exercise was try to refactor multiple 'hard coded' string comparisons
into nested abstract types with public readonly string fields, using .Net
v1.1.
Why? Why is that the goal? The code you posted seems to achieve that,
but why do you want code that looks like that?
These 'abstract' types would be used throughout the solution.
There's nothing abstract about those types. In fact, by virtue of being
"sealed", it's the exact opposite.
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.
Why would you want to "watch" a constant? Did you think it was going to
change? How does putting constants in a nested class address the issue?

I'm not even sure I've used the 2003 version of VS...I might have jumped
straight from VC6 to 2005. I'm not sure what limitations might exist in
the debugger that would present a problem here. But it seems to me that
if you're having trouble with the tools, the most appropriate solution is
to upgrade the tools, rather than try to rearrange your code in a
contrived way.

Pete
Jun 27 '08 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

28
by: joe | last post by:
I have a simple .NET application with two or three listViews which are filled with icons and when the user click on the proper item, they display the related images. I use "image = null ; " for all...
12
by: Steve W. | last post by:
I just read the section (and did the exercise) in the C# Step by Step book that covers Explict Interface Implementation (where you specify in the method implementation the specific interface that...
4
by: Oleg Subachev | last post by:
What good obfuscators/protectors for .NET are on the market now ? -- Best regards, Oleg Subachev subachev@ural.ru
0
by: COHENMARVIN | last post by:
I have a web site where I put my asp.net application in a folder called /asp.net/hotelallocation. I want it to be protected by a password, so I put a web.config file in that folder. But now when...
12
by: Joe Fallon | last post by:
I would like to know the syntax to check that an Object is a String. If it was a number test I might use IsNumeric. But there is no function: IsString (is there?) -- Joe Fallon
0
by: Just Me | last post by:
Consider the following where I generate 2 identical ListViewItems, add one to the ListView and then check to see if the other one is Contained? I get the MM message but not the WW message. So...
4
by: moleskyca1 | last post by:
What operators cannot be virtual and why? I looked at FAQ and found nothing. I think there are operators that cannot be virtual, but I don't know why?
6
by: mcasaurabhsumit | last post by:
Hello Friend, can u send me about cursor? i find it most difficult. What is cursor? How many Types of cursor? how to create each one? what r the benefit of each cursor?
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.