Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# Windows Phone
Hi,
I am trying to read a value from isolated storage and perform a function based on the value.
 
For example if the value is true I will then load some values. However all I get is Cannot implicitly convert type 'string' to 'float'
 
Here is the first part of my code:
private void LayoutRoot_Loaded(object sender, System.Windows.RoutedEventArgs e)
       {
           {
               checkstate.Text +=
               IsolatedStorageSettings.ApplicationSettings["lost"] as string;
               float checks = float.Parse(checkstate.Text);
               if (checks = "true")
               {
 
                   number1.Text = rnd.Next(1, 10).ToString();
                   number2.Text = rnd.Next(1, 10).ToString();
 
and so on
 
Any help is much appreciated, I am just learning how to program so please forgive me for any completely stupid mistakes.
Posted 17-Jul-12 7:05am
Comments
Wes Aday at 17-Jul-12 14:25pm
   
"checks = "true" ... is "true" a float? No it's a string. You cannot do that.
Sergey Alexandrovich Kryukov at 17-Jul-12 16:44pm
   
Besides, it probably meant "==". This is not spelling, just lack of understanding the very basics.
Voted 1.
--SA
Wes Aday at 17-Jul-12 15:06pm
   
Once you figure out the first error, the answer to your next question/error is: "=" is an assignment operator. What you want here is if (checks == true). The "==" (double equals) is a comparison operator.

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Data Types 101
 
A "STRING" is a sequence of characters commonly called "Text"
A "BOOLEAN" is a true or false value.
A "FLOAT" is a precision decimal number.
 
Here is an example of using each one.
 
//STRINGS
string checkState = IsolatedStorageSettings.ApplicationSettings["lost"];
if(checkState == "true")
{
     //Do Stuff!
}
 
//BOOLEAN
bool checkState = false;
if(checkState == true)
{
     //Do Stuff!
}
 
//FLOATS
float checkState = 1.0002;
if(checkState > 1)
{
     //Do Stuff!
}
  Permalink  
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



Advertise | Privacy | Mobile
Web04 | 2.8.140709.1 | Last Updated 17 Jul 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid