Char test. Consider a string. We can test it with complex methods with StartsWith or EndsWith. Or we can test individual strings, giving our logic more flexibility.
Specialized logic. We can also arrange if-tests with chars to avoid repeated work—for example, if we want to test multiple strings starting with a letter, we can test that value once.
A simple example. Here is a simple example of testing the first letter in a string. Here we see if the string equals the lowercase letter "t."
using System;
class Program
{
static void Main()
{
string value = "test";
// See if first char is the lowercase T.if (value[0] == 't')
{
Console.WriteLine("First char is t");
}
}
}First char is t
Benchmark, char testing. Suppose we need to test a string thousands to billions of times. We benchmark an alternative way of comparing constant strings.
Dot Net Perls is a collection of tested code examples. Pages are continually updated to stay current, with code correctness a top priority.
Sam Allen is passionate about computer languages. In the past, his work has been recommended by Apple and Microsoft and he has studied computers at a selective university in the United States.