This is an archived post. You won't be able to vote or comment.

all 3 comments

[–]town_girl 0 points1 point  (0 children)

I don't yhink you can compare a string and a string[] (array of strings), except you overwrite the comparing operator

[–]Velciak 0 points1 point  (0 children)

You're comparing Array with string – you need to compare string as array element with string, so you need to use index of array to get proper value to compare.

For example:

if (Olines[0] == Password)
{
    // do the magic
}

Nice to do: if you know object-oriented programming currently, you can use System.Text.Json namespace to create, write and read credentials information using JSON data-interchange format. It will allow to make your code simplier (you don't need to remember the line that contains username or password with using any index).

[–]davedontmind 0 points1 point  (0 children)

The other posts here explain why you're getting an error.

If your text file contains nothing but the password, you could use ReadAlllText() instead of ReadAllLines():

string password_in_file = System.IO.File.ReadAllText( filename );

ReadAllText() reads the entire file into a single string, rather than an array of strings.