How can I do to remove the string s

  • Thread starter Thread starter Tony Johansson
  • Start date Start date
T

Tony Johansson

Hello!

If I do the following I get compile error says It's not possible to implicit
convert the type string to bool
Label4.Text = "Browser support cookies : " + Request.Browser.Cookies ?
"true" : "false";

Can I write in another way so I can remove the s string in this code.


protected void Page_Load(object sender, EventArgs e)
{
string s;
Label1.Text = "Application path is : " + Request.Path;
Label2.Text = "OS platform is : " + Request.Browser.Platform;
Label3.Text = "Browser type is : " + Request.Browser.Type;
s = Request.Browser.Cookies ? "true" : "false";
Label4.Text = "Browser support cookies : " + s;
s = Request.Browser.VBScript ? "true" : "false";
Label5.Text = "Browser support VBScript : " + s;
s = Request.Browser.JavaScript ? "true" : "false";
Label6.Text = "Browser support JavaScript : " + s;
Label7.Text = "Browser is using :" + Request.HttpMethod + " data
transfer method";
}

//Tony
 
Hello!

If I do the following I get compile error says It's not possible to implicit
convert the type string to bool
Label4.Text = "Browser support cookies : " + Request.Browser.Cookies ?
"true" : "false";

Can I write in another way so I can remove the s string in this code.

Try:

Label4.Text = "Browser support cookies : " + (Request.Browser.Cookies ?
"true" : "false");

or maybe:

Label4.Text = "Browser support cookies : " + Request.Browser.Cookies;

Arne
 
I found it myself I just used Convert.ToString in this way.
Label4.Text = "Browser support cookies :" +
Convert.ToString(Request.Browser.Cookies ? true : false);

//Tony
 
I found it myself I just used Convert.ToString in this way.
Label4.Text = "Browser support cookies :" +
Convert.ToString(Request.Browser.Cookies ? true : false);

That code can be shortened!

Label4.Text = "Browser support cookies :" + Request.Browser.Cookies;

works the same way.

Arne
 
Convert.ToString(Request.Browser.Cookies ? true : false);

Stop and think about this code:

Request.Browser.Cookies ? true : false

The Cookies property is a Boolean. You're testing it (for "trueness") and
returning...a Boolean! Just use the value itself instead of translating it
into...itself!
 
Back
Top