Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions snippets/csharp/VS_Snippets_CLR/string.compare4/CS/comp4.cs
Original file line number Diff line number Diff line change
@@ -1,25 +1,27 @@
//<snippet1>
// Sample for String.Compare(String, Int32, String, Int32, Int32, Boolean)
using System;

class Sample
{
public static void Main()
{
//<snippet1>
String str1 = "MACHINE";
String str2 = "machine";
String str;
int result;

Console.WriteLine();
Console.WriteLine("str1 = '{0}', str2 = '{1}'", str1, str2);

Console.WriteLine("Ignore case:");
result = String.Compare(str1, 2, str2, 2, 2, true);
str = ((result < 0) ? "less than" : ((result > 0) ? "greater than" : "equal to"));
Console.Write("Substring '{0}' in '{1}' is ", str1.Substring(2, 2), str1);
Console.Write("{0} ", str);
Console.WriteLine("substring '{0}' in '{1}'.", str2.Substring(2, 2), str2);
Console.WriteLine();

Console.WriteLine("Honor case:");
result = String.Compare(str1, 2, str2, 2, 2, false);
str = ((result < 0) ? "less than" : ((result > 0) ? "greater than" : "equal to"));
Expand All @@ -37,6 +39,6 @@ public static void Main()
Honor case:
Substring 'CH' in 'MACHINE' is greater than substring 'ch' in 'machine'.
*/
//</snippet1>
}
}
//</snippet1>
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ bool TestForNullOrEmpty(string s)
string s2 = "";
Console.WriteLine(TestForNullOrEmpty(s1));
Console.WriteLine(TestForNullOrEmpty(s2));

// The example displays the following output:
// True
// True
// </Snippet1>
}
}