convert hybridDictionary to string

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi all

I have a shopping cart object which I'd like to send the contents via an
e-mail.

I get an error saying 'hybridDictionary' cannot be converted to string.

Does anyone know how to do this or point me in the right direction?

Thanks
 
If you could convert a dictionary into a string, it would end up as one
long string of values, without line breaks or anything. That's probably
not what you want anyway.

Create a StringBuilder, loop through the items in the dictionary and add
the text for each item to the StringBuilder.
 
Thanks for your reply.

Could you give an example of a "string builder" I'm fairly new to asp.net 2.0
 
Ok, here goes:

// Create a StringBuilder
StringBuilder builder = new StringBuilder();

// Add some text
builder.Append("Some text.");

// Add an integer
int answer = 42;
builder.Append(answer);

// Add a line break
builder.AppendLine();

// Things like dates and floating point values should be formatted
builder.AppendFormat("yyyy-MM-dd HH:mm:ss", DateTime.Now);

// You can stack appends
builder.Append("Number ").Append(answer).AppendLine(" again");

// Finally get the complete string
string message = builder.ToString();
 
Thanks Göran I'll try that

James

Göran Andersson said:
Ok, here goes:

// Create a StringBuilder
StringBuilder builder = new StringBuilder();

// Add some text
builder.Append("Some text.");

// Add an integer
int answer = 42;
builder.Append(answer);

// Add a line break
builder.AppendLine();

// Things like dates and floating point values should be formatted
builder.AppendFormat("yyyy-MM-dd HH:mm:ss", DateTime.Now);

// You can stack appends
builder.Append("Number ").Append(answer).AppendLine(" again");

// Finally get the complete string
string message = builder.ToString();
 
Back
Top