string str1 = "Hello World!";
string str2 = "Hello World!";
if (str1 == str2)
{
Console.WriteLine("equal");
} else
{
Console.WriteLine("not equal");
}
What i an trying to do is make a authentication system where you input a name and it looks at a array and sees if they can go in or not. When i try doing it like you have said it says it cant convert a string[] to a stringThe problem appears to be that one of your strings is a string array (string[]). It's hard to say without seeing the actual code. But, the following is how you compare two strings.
C#:string str1 = "Hello World!"; string str2 = "Hello World!"; if (str1 == str2) { Console.WriteLine("equal"); } else { Console.WriteLine("not equal"); }
using System.Linq;
string[] usernames = new string[]{ "user1", "user2" };
string user = "user1";
if (usernames.Contains(user))
{
Console.WriteLine("user found");
} else
{
Console.WriteLine("user not found");
}
I am now getting this error when trying to put “using system.linqBy using the System.Linq namespace, arrays get a Contains function that can find a value inside them. At the top of the program, addThen, we change our comparison:C#:using System.Linq;
C#:string[] usernames = new string[]{ "user1", "user2" }; string user = "user1"; if (usernames.Contains(user)) { Console.WriteLine("user found"); } else { Console.WriteLine("user not found"); }
using System;
using System.Linq;
namespace Stringcompare
{
class Program
{
static void Main(string[] args)
{
string[] usernames = new string[]{ "user1", "user2" };
string user = "user1";
if (usernames.Contains(user))
{
Console.WriteLine("user found");
} else
{
Console.WriteLine("user not found");
}
}
}
}
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.