|
I remember there used to be a hidden Eight Ball in MS Access, good times. There was something hidden in most of the MS Office type applications back then; Excel had a little 3D world that you could fly around in!
My current favourite word is: Sammidge!
-SK Genius
Game Programming articles start - here[ ^]-
|
|
|
|
|
Hi
I have problem returning an XML document in my c# code. The code I am using is as follows:
string xmlString = null;
MemoryStream memoryStream = new MemoryStream();
XmlSerializer xs = new XmlSerializer(typeof(T));
XmlTextWriter xmlTextWriter = new XmlTextWriter(memoryStream, Encoding.UTF8);
xs.Serialize(xmlTextWriter, obj);
memoryStream = (MemoryStream)xmlTextWriter.BaseStream;
xmlString = UTF8ByteArrayToString(memoryStream.ToArray());
return xmlString;
private static string UTF8ByteArrayToString(byte[] characters)
{
UTF8Encoding encoding = new UTF8Encoding();
string constructedString = encoding.GetString(characters);
return (constructedString);
}
The problem I have is when the xml string is returned, the namespace and declaration at the start of the xml string is not in a well formed xml document.
What it is doing is inserting / in front of the equal sign in the name space, thus:
Therefore, I am looking for advice on how to stop this happening.
Can anyone help?
Thanks
|
|
|
|
|
Your example xml header is not showing up. Maybe you need to enclose it in code tags or pre tags.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
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.
|
|
|
|