Click here to Skip to main content
15,885,546 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
this is my code

C#
if (setcdate.Content == "00/00/0000")
       {
       }
       else
       {
}


and this is my error

C#
Warning 1   Possible unintended reference comparison; to get a value comparison, cast the left hand side to type 'string'   C:\Users\Kyle\documents\visual studio 2010\Projects\DaysUntill\DaysUntill\MainWindow.xaml.cs    104 17  DaysUntill


and setcdate is a label

can some plz help me?
Posted

1 solution

You don't show enough code, but the simple fact is: Content is not string (most likely, System.Object), so how can you compare the two objects? You can use string compare = setcdata.Content as string. In case this is not string it will return null which give correct comparison: null == "00/00/0000" will give you false.

However, I'm pretty much sure the whole idea of this comparison is wrong. Why doing it?

—SA
 
Share this answer
 
Comments
Dr.Walt Fair, PE 18-Jul-11 22:42pm    
You beat me to it! Content is an object, so the comparison is between a string on the right and an object reference on the left. The cure is to get the string from the object, just as the warning says, but I'd probably use Content.ToString() since it clearly shows what is being done.
Sergey Alexandrovich Kryukov 18-Jul-11 23:30pm    
Thank you, Walt. That might be the solution, too. As I say, I doubt whole thing make sense, not even mentioning using immediate constant by literal "00/00/0000", what the hell?
--SA
[no name] 19-Jul-11 6:32am    
well this is my whole code


private void Window_Loaded(object sender, RoutedEventArgs e)
{


mdate.Content = DateTime.UtcNow.ToShortDateString();

DateTime dt2 = Convert.ToDateTime(mdate.Content);
dt2 = dt2.Date.AddDays(1);
cdate.Content = dt2.ToShortDateString();

pdate.Content = mdate.Content;

//load settings
//combobox
comboBox1.Text = DateUntill.Properties.Settings.Default.bgcolor;
//set date
setcdate.Content = DateUntill.Properties.Settings.Default.date1;
setpdate.Content = DateUntill.Properties.Settings.Default.date2;

//progressbar
if (setcdate.Content == "00/00/0000")
{
}
else
{
//progress bar
DateTime dtt1 = Convert.ToDateTime(mdate.Content);
DateTime dtt2 = Convert.ToDateTime(cdate.Content);
TimeSpan tss = dtt2 - dtt1;
int days = tss.Days;

DateTime PP1 = Convert.ToDateTime(pdate.Content);
DateTime PP2 = Convert.ToDateTime(cdate.Content);
TimeSpan st = PP2 - PP1;
int dayss = st.Days;

progressBar1.Maximum = dayss;
progressBar1.Value = days;


//--
//this is the cdate and the mdate
DateTime ooo = Convert.ToDateTime(mdate.Content);
DateTime oooo = Convert.ToDateTime(setcdate.Content);
TimeSpan tos = oooo - ooo;
int dayso = tos.Days;
label14.Content = tos.Days;

//ads the texts blocks and colours them with the date
this.SP1.Children.Clear();
for (int i = 0; i < tos.Days; i++)
{
TextBlock TXB = new TextBlock();

TXB.TextWrapping = TextWrapping.Wrap;

DateTime BB = Convert.ToDateTime(mdate.Content);
TXB.Text = BB.AddDays(i).ToShortDateString();
TXB.Width = 35;
TXB.Name = "T" + i.ToString();

if (TXB.Text == Convert.ToString(mdate.Content))
{
TXB.Background = new LinearGradientBrush(Colors.Blue, Colors.LightCyan, new Point(0, 0), new Point(1, 1));
}
else
{
TXB.Background = new LinearGradientBrush(Colors.Red, Colors.LightCyan, new Point(0, 0), new Point(1, 1));
}

this.SP1.Children.Add(TXB);
}
}

var color = (Color)ColorConverter.ConvertFromString(comboBox1.Text);
this.Background = new LinearGradientBrush(color, Colors.White, 90);
this.progressBar1.Background = new SolidColorBrush (color);

this.Height = DateUntill.Properties.Settings.Default.sheight;
this.Width = DateUntill.Properties.Settings.Default.swidth;
this.Top = DateUntill.Properties.Settings.Default.Tlocation;
this.Left = DateUntill.Properties.Settings.Default.Llocation;
textBox1.Text = DateUntill.Properties.Settings.Default.textbox1stext;


}

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900