C# help needed

  • Thread starter Thread starter Jon Paal
  • Start date Start date
J

Jon Paal

how do I set the cast in C# ?

Compiler Error Message: CS0266: Cannot implicitly convert type 'object' to 'string'. An explicit conversion exists (are you missing
a cast?)

Source Error:



Line 6: string t = System.Web.HttpContext.Current.Profile.GetPropertyValue("SiteTheme");
 
Not sure what the particular object is that you are referencing (I am
rather new myself), but try this:

string t =
(string)System.Web.HttpContext.Current.Profile.GetPropertyValue("SiteTheme");

Jeff
 
How about this?
string t =
System.Web.HttpContext.Current.Profile.GetPropertyValue("SiteTheme").ToString();
 
Let me explain the compiler error:
Compiler Error Message: CS0266: Cannot implicitly convert type 'object' to 'string'. An explicit conversion exists (are you missing

indeed 'System.Web.HttpContext.Current.Profile.GetPropertyValue("SiteTheme")'
return an object.

How do you know it's a string? Are you sure it's not a bug?

if it's a bug: correct it ;-)

If you know for sure it's a string, let it be known to the compiler by making a cast, just like in C
OPEN_PARENTHESIS TYPE CLOSE_PARENTHESIS

as in:
(string)

object o = "a string";
string s = (string) o;
 
You convert instead of casting. Try Convert.ToString()

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
You can lead a fish to a bicycle,
but it takes a very long time,
and the bicycle has to *want* to change.
 
Back
Top