By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,002 Members | 2,137 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,002 IT Pros & Developers. It's quick & easy.

Please help convert the following Java to C#

P: n/a
Please help me convert the following Java to C#

class ProgramChoice {
private Class cls;
private String text;

ProgramChoice(String text, Class cls) {
this.cls = cls;
this.text = text;
}

public String toString() { return text; }
Class value() { return cls; }
}

Any help will be greatly appreciated.
Charles
Aug 24 '08 #1
Share this Question
Share on Google+
6 Replies


P: n/a
Charles wrote:
Please help me convert the following Java to C#

class ProgramChoice {
private Class cls;
private String text;

ProgramChoice(String text, Class cls) {
this.cls = cls;
this.text = text;
}

public String toString() { return text; }
Class value() { return cls; }
}

Any help will be greatly appreciated.
I would say something like:

internal class ProgramChoice
{
private Type cls;
private string text;

internal ProgramChoice(string text, Type cls) {
this.cls = cls;
this.text = text;
}

public override string ToString()
{
return text;
}

internal Type Value
{
get { return cls; }
}
}

Java default/package and .NET internal is not the exact same,
but will do in many cases.

Arne
Aug 24 '08 #2

P: n/a
"Charles" <Ch*****@discussions.microsoft.comwrote:
Please help me convert the following Java to C#
I think it would be what you see below. I've prepended an underscore to
field names according to C# naming conventions.

Eq.
class ProgramChoice
{
private object _cls;
private string _text;

public ProgramChoice(string text, object cls)
{
_cls = cls;
_text = text;
}

public override string ToString()
{
return _text;
}

public object Value
{
get { return _cls; }
}
}
Aug 24 '08 #3

P: n/a
"Paul E Collins" <fi******************@CL4.orgwrote:
I've prepended an underscore to field names according to C# naming
conventions.
Curses, I was getting mixed up with something else, wasn't I? Apologies. I
don't think C# has any such convention.

Eq.
Aug 24 '08 #4

P: n/a
Paul E Collins wrote:
"Paul E Collins" <fi******************@CL4.orgwrote:
>I've prepended an underscore to field names according to C# naming
conventions.

Curses, I was getting mixed up with something else, wasn't I? Apologies. I
don't think C# has any such convention.
Some people do use _ prefix, but it is not a majority.

Arne
Aug 24 '08 #5

P: n/a
No need to get undies bundled. The underscore is a common prefixed notation
convention as is m_ which you can see Dino Esposito use as well as others
who picked up the habit to visually decorate text to give it a visual
property where the language itself and all other conventions lack such
characteristics. However while such conventions are cononical they are not
found in the official language specifications. Which is why people made them
up in the first place.

I was an architect and we use dozens of symbolic references to indicate type
in the same context as we do when decorating OOP. I've been wondering lately
how we will map them to the OOP objects they describe now that OOP has
become the defacto way to model objects.

"Arne Vajhøj" <ar**@vajhoej.dkwrote in message
news:48***********************@news.sunsite.dk...
Paul E Collins wrote:
>"Paul E Collins" <fi******************@CL4.orgwrote:
>>I've prepended an underscore to field names according to C# naming
conventions.

Curses, I was getting mixed up with something else, wasn't I? Apologies.
I don't think C# has any such convention.

Some people do use _ prefix, but it is not a majority.

Arne
Aug 24 '08 #6

P: n/a
HillBilly wrote:
No need to get undies bundled. The underscore is a common prefixed
notation convention as is m_ which you can see Dino Esposito use as well
as others who picked up the habit to visually decorate text to give it a
visual property where the language itself and all other conventions lack
such characteristics. However while such conventions are cononical they
are not found in the official language specifications. Which is why
people made them up in the first place.
It is not that widely used.

One reason could be that the official MS design guide explicit
recommends not using prefixes in field names.

Arne
Aug 24 '08 #7

This discussion thread is closed

Replies have been disabled for this discussion.