سلام
برای مقایسه می تونی از هر روش که می خوای استفاده کنی:
// Internal strings that will never be localized.
string root = @"C:\users";
string root2 = @"C:\Users";
// Use the overload of the Equals method that specifies a StringComparison.
// Ordinal is the fastest way to compare two strings.
bool result = root.Equals(root2, StringComparison.Ordinal);
Console.WriteLine("Ordinal comparison: {0} and {1} are {2}", root, root2,
result ? "equal." : "not equal.");
// To ignore case means "user" equals "User". This is the same as using
// String.ToUpperInvariant on each string and then performing an ordinal comparison.
result = root.Equals(root2, StringComparison.OrdinalIgnoreCase);
Console.WriteLine("Ordinal ignore case: {0} and {1} are {2}", root, root2,
result ? "equal." : "not equal.");
// A static method is also available.
bool areEqual = String.Equals(root, root2, StringComparison.Ordinal);
دوم :
label3.Text = sentence_counter.ToString;
شما قصدت اینه که بفهمی چه تعداد نقطه در رشته وجود داره بهتره از این کد که خیلی سریعتر عمل می کنه استفاده کنی اگر هم اصرار داری رشته رو split کنی بعد از بدست آوردن تعداد این کار رو بکن.
int count=txt_Orig.Text.Count(ch => ch=='.');
کد بالا با استفاده از Lambda Expression بود این کد با LINQ کار می کنه:
class QueryAString
{
static void Main()
{
string aString = "ABCDE9.N..454";
// Select only those characters that are numbers
IEnumerable<char> stringQuery =
from ch in aString
where ch== '.'
select ch;
// Call the Count method on the existing query.
int count = stringQuery.Count();
Console.WriteLine("Count = {0}", count);
}
}
/* Output:
Count = 3
*/