using System;
namespace ConsoleApplication_C_Sharp
{
class Program
{
static void Main(string[] args)
{
string[] s = { "PHP", "C", "C++", "C#", "Java", "JavaScript",
"VB.NET", "VB6", "Pascal", "Python"};
Char[] characters = { 'C', 'J', 'V', 'P', 'D'};
foreach (var ch in characters)
Console.WriteLine("One or more strings begin with '{0}': {1}",
ch,
Array.Exists(s, (new SearchString(ch)).StartsWith));
}
}
public class SearchString
{
Char firstChar;
public SearchString(Char firstChar)
{
this.firstChar = Char.ToUpper(firstChar);
}
public bool StartsWith(String s)
{
if (String.IsNullOrEmpty(s)) return false;
if (s.Substring(0, 1).ToUpper() == firstChar.ToString())
return true;
else
return false;
}
}
}
/*
run:
One or more strings begin with 'C': True
One or more strings begin with 'J': True
One or more strings begin with 'V': True
One or more strings begin with 'P': True
One or more strings begin with 'D': False
*/