+ 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

27th May 2018, 8:14 PM
DWas
DWas - avatar
7 ответов
+ 4
DWas Please show your attempt. I will help you make it. @ mention me when you link your code.
27th May 2018, 8:49 PM
Manual
Manual - avatar
+ 4
Ace thanks a lot man you just made my day😀
27th May 2018, 9:33 PM
DWas
DWas - avatar
+ 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
27th May 2018, 8:53 PM
Ipang
+ 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
27th May 2018, 10:10 PM
Ipang
+ 2
thanks Ipang . Have been wondering about string.equal and == . thanks for that
27th May 2018, 10:12 PM
DWas
DWas - avatar
+ 1
https://code.sololearn.com/cQCI428oX4v0/?ref=app Manual i hope you understand the intention of my program
27th May 2018, 9:09 PM
DWas
DWas - avatar
+ 1
Ace i have updated my code..would you mind taking a look
27th May 2018, 9:24 PM
DWas
DWas - avatar