The C# StartsWith function is utilized to verify if the initial part of the given string object corresponds with the specified string.
Signature
Example
public bool StartsWith(String str)
public bool StartsWith(String, Boolean, CultureInfo)
public bool StartsWith(String, StringComparison)
Parameter
The str parameter is a string type used to verify the start of a string.
Return
It returns boolean value.
C# String StartsWith Method Example
Example
using System;
public class StringExample
{
public static void Main(string[] args)
{
string s1 = "Hello C Sharp";
bool b1 = s1.StartsWith("h");
bool b2 = s1.StartsWith("H");
Console.WriteLine(b1);
Console.WriteLine(b2);
}
}
Output:
Output
False
True