[SOLVED] C# Bool Variable always false

Status
Not open for further replies.

rkt_167

Junior Member level 1
Joined
Aug 9, 2013
Messages
19
Helped
3
Reputation
6
Reaction score
3
Trophy points
3
Activity points
163
hi all,

I am comparing two strings:

Code C# - [expand]
1
bool d = (String.Equals(ethernetHeader.Source,staticForm.textBox1.Text.ToString()));



this statement is always false even in console both are same as below..
ethernetHeader.Source=00:25:64:4F:219
textBox1.Text=00:25:64:4F:219

any possible reason??

thanks,
 

should work - could you have spaces or a newline in one of the strings? try printing the strings e.g.
Code:
            Console.WriteLine(" '{0}' '{1}' {2}\n", ethernetHeader.Source, staticForm.textBox1.Text.ToString(), d);
you should then see if the strings are identical

also you don't require the ToSting() in staticForm.textBox1.Text.ToString()
staticForm.textBox1.Text returns a string
 
thanks horace1,
Code:
bool d = (String.Equals(ethernetHeader.Source.ToString(), staticForm.textBox1.Text.Trim()));

I used Trim() and now it is working fine.
 

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…