c# check if string is in array
using System;
namespace Example
{
class Program
{
static void Main(string[] args)
{
string[] planets = { "Mercury", "Venus",
"Earth", "Mars", "Jupiter",
"Saturn", "Uranus", "Neptune" };
if (planets.Contains("Jupiter"))
{
Console.WriteLine("It contains Jupiter");
}
Console.WriteLine("One or more planets begin with 'M': {0}",
Array.Exists(planets, element => element.StartsWith("M")));
Console.WriteLine("One or more planets begin with 'T': {0}",
Array.Exists(planets, element => element.StartsWith("T")));
Console.WriteLine("Is Pluto one of the planets? {0}",
Array.Exists(planets, element => element == "Pluto"));
}
}
}
// The example displays the following output:
// One or more planets begin with 'M': True
// One or more planets begin with 'T': False
// Is Pluto one of the planets? False
Also in C#:
- vb.net check if datatable has rows
- c# how to convert string to int
- c# how to use inovke
- validating file upload asp.net core mvc
- see if two string arrays are equal c#
- c# find index element array
- c# trim string
- fibonacci series using recursion
- unity move character
- unity c# public all codes
- how to make error sound c#
- dynamic group by expression C#
- c# string code ascii
- how to make a pause feautre in unity
- c# typeof
- how to reference scripts in other scenes unity
- cannot convert string to generic type c#
- lat long data type c#
- unity normalize vector2
- uinput dialog uwp c#
- c# print expression tree
- c# string
- c# select first value from list
- unity making homing rocket