The Windows Contains method is used in C# to determine whether a given string of characters is contained within another string or not. It is part of the System.Windows.Forms namespace library.
Example 1:
string message = "Hello, world!"; if (message.Contains("world")) { Console.WriteLine("The word 'world' was found!"); } else { Console.WriteLine("The word 'world' was not found."); }
In this example, the Contains method is used to search for the word "world" within the string variable message. If the word is found, the program will display a message indicating that it was found. Otherwise, it will display a message indicating that it was not found.
Example 2:
List names = new List { "John", "Mary", "Tom", "Lisa" }; if (names.Contains("Mary")) { Console.WriteLine("The name 'Mary' was found in the list."); } else { Console.WriteLine("The name 'Mary' was not found in the list."); }
In this example, the Contains method is used to search for the name "Mary" within a list of names. If the name is found, the program will display a message indicating that it was found. Otherwise, it will display a message indicating that it was not found.
Package library: System.Windows.Forms.
C# (CSharp) Windows.Contains - 19 examples found. These are the top rated real world C# (CSharp) examples of Windows.Contains from package terrafx.interop.windows extracted from open source projects. You can rate examples to help us improve the quality of examples.