Click here to Skip to main content
12,690,575 members (33,862 online)
Rate this:
Please Sign up or sign in to vote.
See more: C# Windows Phone
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 8:05am
Wes Aday 17-Jul-12 14:25pm
"checks = "true" ... is "true" a float? No it's a string. You cannot do that.
Sergey Alexandrovich Kryukov 17-Jul-12 16:44pm
Besides, it probably meant "==". This is not spelling, just lack of understanding the very basics.
Voted 1.
Wes Aday 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
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.

string checkState = IsolatedStorageSettings.ApplicationSettings["lost"];
if(checkState == "true")
     //Do Stuff!

bool checkState = false;
if(checkState == true)
     //Do Stuff!

float checkState = 1.0002;
if(checkState > 1)
     //Do Stuff!

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

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

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100