|
namespace VDP{
public class GlobalVar{
Private Const _DIAMONDS As String = "♦"
public string DIAMONDS
{
get { return _DIAMONDS };
}
}
}
namespace VDP{
public partial class frmMain: Form{
Switch (x){
case globalVar.DIAMONDS:
}
error: A Constant Value is expected on this line: case globalVar.Diamonds:
Not sure where I went wrong. All I want to do is compare x to my Const DIMAONDS
|
|
|
|
|
Usually you don't copy VB.NET code into C#.
|
|
|
|
|
Thanks for the reply, however it wasn't very helpful.
My task is to convert a program that I wrote from VB to C#. I am not copying the VB directly in. I am trying to re-write the program in C#. As a complete novice, all I can do is try. Are you saying that all of my code is completely wrong?
|
|
|
|
|
yogi_bear_79 wrote: Private Const _DIAMONDS As String = "♦"
public string DIAMONDS
Try changing the above to
private const char _DIAMONDS = '♦';
public char DIAMONDS
{
...
|
|
|
|
|
Thanks, I made the suggested changes in my GlobalVar class. I now get an error on this line:
private const char _DIAMONDS = '♦';
Cannot implicitily convert type 'string' to 'char'
|
|
|
|
|
yogi_bear_79 wrote: private const char _DIAMONDS = '♦';
Cannot implicitily convert type 'string' to 'char'
This looks OK, are you sure the quote characters are definitely single quotes? If you use double quotes then the compiler thinks it's a string rather than a single character.
|
|
|
|
|
That's not really the "right" error you know, it should say "Syntax error: this is C#, not VB"
Blind suggestion (untested)
namespace VDP
{
public class GlobalVar
{
public const string DIAMONDS = "♦";
}
}
namespace VDP
{
public partial class frmMain : Form
{
switch (x)
{
case globalVar.DIAMONDS:
break;
}
}
}
Hint: the right side of a case should be an actual constant, not a "thing that is logically constant", but syntactically constant.
Good luck
|
|
|
|
|
Thanks, like I said, I am just a novice this is my first project to convert the Poker game I wrote in lesson 1 to C#.
I get the following error after following your suggestions:
Member VDP.GlobalVar.DIAMONDS cannot be accessed with an instance referance; qualify it with a type name instead
|
|
|
|
|
I tried using "♦"; in lieu of "♦"; It did not create the diamond symbol. Do I need to do something else? I had wanted to use code versus symbols on my original VB code but was unable to get it to work.
|
|
|
|
|
I don't really see what you mean here, what do you mean?
|
|
|
|
|
Sorry i typed "&9830;"; and it converted to the Diamonds symbol for me. I was trying to say I couldn't get my program to display the Diamond when I used "&9830;"
|
|
|
|
|
oh, yea, should have been \u9830 or something like that - I didn't type it on purpose, it accidentally happened, dunno why
|
|
|
|
|
Try this.........
namespace CodeSnippets
{
class Global
{
public const string strOperator = "+";
}
public class Example
{
private void Go()
{
bool i;
switch (x)
{
case Global.strOperator:
{
i = true;
break;
}
}
}
}
}
Thanks
Md. Marufuzzaman
Don't forget to click [Vote] / [Good Answer] on the post(s) that helped you.
I will not say I have failed 1000 times; I will say that I have discovered 1000 ways that can cause failure – Thomas Edison.
|
|
|
|
|
Hi,
look at the line numbers, the error message points here: case globalVar.DIAMONDS:
and of course it is right, you made _DIAMONDS a const, however DIAMONDS isn't const, it is a property.
the solution is easy: make your _DIAMONDS a public const and get rid of the property and the underscore.
Luc Pattyn
I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages
Local announcement (Antwerp region): Lange Wapper? Neen!
|
|
|
|
|
ok I changed it to
public const string DIAMONDS = "♦";
I have two lines of code thus far that utilize DIAMONDS
1: TempDeck[x] = TemDeck[x] + of + globalVar.DIAMONDS
2: Case globalVar.DIAMONDS
The first line of code was previoulsy working (or at least not erroring out). Now all references return the following error:
Member VDP.GlobalVar.DIAMONDS cannot be accessed with an instance referance; qualify it with a type instead. I had originally started out with public const string DIAMONDS but switched it after having other problems
|
|
|
|
|
ok, I got it to work. I did away with :
GlobalVar globalVar = new GlobalVar;
And change the code from globalVar to GlobalVar.
It compiles but have other problems that need fixed before I can see if it diplays the suits correctly, thanks..
|
|
|
|
|
You should perhaps use an online VB to C# converter to fix all this, or just buy a C# book and read it. This is half C# and half VB
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
The online converter @ http://www.developerfusion.com/tools/convert/vb-to-csharp/ gave me that code
|
|
|
|
|
Really ? Then it sucks, I guess you need to buy a C# book and do it yourself, or buy a converter, the commercial ones do a much better job.
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
Not a huge deal..I have the code from VB, I just need to learn how to do e the same or better with C#. I have a C# book, but no book I've ever seen tells you everything. This is an on-line class, so help is minimal. It is also my last class for my BA-CS, as a Network/Server administrator I do little programming so buying software to do this one project doesn't make much sense.
|
|
|
|
|
yogi_bear_79 wrote: I have a C# book, but no book I've ever seen tells you everything.
Most books will tell you how to define variables, however
One thing you could do, is download some C# projects from code project, and just look at the code to get a feel for how it looks different, things like
int i = 0;
instead of
dim int as i = 0
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
I agree, and I have the book and the net for that. This wasn't so much how to type the syntax as the proper useage for what I wanted. I basically came full circle here. public const string is what I started out with, just wasn't working.
|
|
|
|
|
I see Luc helped you, but also, why not use an enumeration?
|
|
|
|
|
Seeing only one constant, I was going to suggest no such thing.
It could become a reply in a future thread though.
Luc Pattyn
I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages
Local announcement (Antwerp region): Lange Wapper? Neen!
|
|
|
|
|
Not having the heart to club him, I figured I'd call a spade a spade.
|
|
|
|