+ 2
Conditional c#
Hey guys iam new to c# and i have ran across a problem. How to use conditional for strings. I want to to develop a program which asks user to enter a name. If the user supplied name matches a particular name then condition is true. Else it is false. How to? Plz help
8 Respostas
+ 4
DWas Please show your attempt.
I will help you make it.
@ mention me when you link your code.
+ 4
Ace thanks a lot man
you just made my day😀
+ 3
Just a hint to get you started with, you may use Contains method of the String class:
https://msdn.microsoft.com/en-us/library/dy85x1sa(v=vs.110).aspx
+ 3
DWas
String.Contains is case sensitive, but in the link on my previous post you see a custom example to compare String with case sensitivity option. Here's an example using String.Contains:
using System;
namespace Example
{
class TextContains
{
static void Main(string[] args)
{
String names = "Alfred Brad Corey Dennis Elias Fred George Harris";
String name = Console.ReadLine();
if(names.Contains(name))
{
Console.WriteLine("Yep\n");
}
else
{
Console.WriteLine("Nope\n");
}
}
}
}
String comparison in C# is done (commonly) using String.Equals, not the == operator.
[String.Equals]
https://msdn.microsoft.com/en-us/library/858x0yyx(v=vs.110).aspx
[How to compare String]
https://docs.microsoft.com/en-us/dotnet/csharp/how-to/compare-strings
Hth, cmiiw
+ 2
thanks Ipang . Have been wondering about string.equal and == . thanks for that
+ 1
https://code.sololearn.com/cQCI428oX4v0/?ref=app
Manual
i hope you understand the intention of my program
+ 1
Ace i have updated my code..would you mind taking a look