diff --git a/snippets/csharp/VS_Snippets_CLR/string.contains/CS/cont.cs b/snippets/csharp/VS_Snippets_CLR/string.contains/CS/cont.cs index 9021723883e..86fa86b3a23 100644 --- a/snippets/csharp/VS_Snippets_CLR/string.contains/CS/cont.cs +++ b/snippets/csharp/VS_Snippets_CLR/string.contains/CS/cont.cs @@ -1,24 +1,24 @@ -// -using System; +using System; class Example { public static void Main() { - string s1 = "The quick brown fox jumps over the lazy dog"; - string s2 = "fox"; - bool b = s1.Contains(s2); - Console.WriteLine("'{0}' is in the string '{1}': {2}", - s2, s1, b); - if (b) { - int index = s1.IndexOf(s2); - if (index >= 0) - Console.WriteLine("'{0} begins at character position {1}", - s2, index + 1); - } + // + string s1 = "The quick brown fox jumps over the lazy dog"; + string s2 = "fox"; + bool b = s1.Contains(s2); + Console.WriteLine("'{0}' is in the string '{1}': {2}", + s2, s1, b); + if (b) { + int index = s1.IndexOf(s2); + if (index >= 0) + Console.WriteLine("'{0} begins at character position {1}", + s2, index + 1); + } + // This example display the following output: + // 'fox' is in the string 'The quick brown fox jumps over the lazy dog': True + // 'fox begins at character position 17 + // } } -// This example display the following output: -// 'fox' is in the string 'The quick brown fox jumps over the lazy dog': True -// 'fox begins at character position 17 -// \ No newline at end of file diff --git a/snippets/csharp/VS_Snippets_CLR/string.length/CS/length.cs b/snippets/csharp/VS_Snippets_CLR/string.length/CS/length.cs index 0ace269d883..a9b783a9178 100644 --- a/snippets/csharp/VS_Snippets_CLR/string.length/CS/length.cs +++ b/snippets/csharp/VS_Snippets_CLR/string.length/CS/length.cs @@ -1,20 +1,21 @@ -// -using System; +using System; class Sample { public static void Main() { - string str = "abcdefg"; - Console.WriteLine("1) The length of '{0}' is {1}", str, str.Length); - Console.WriteLine("2) The length of '{0}' is {1}", "xyz", "xyz".Length); - - int length = str.Length; - Console.WriteLine("3) The length of '{0}' is {1}", str, length); + // + string str = "abcdefg"; + Console.WriteLine("1) The length of '{0}' is {1}", str, str.Length); + Console.WriteLine("2) The length of '{0}' is {1}", "xyz", "xyz".Length); + + int length = str.Length; + Console.WriteLine("3) The length of '{0}' is {1}", str, length); + + // This example displays the following output: + // 1) The length of 'abcdefg' is 7 + // 2) The length of 'xyz' is 3 + // 3) The length of 'abcdefg' is 7 + // } } -// This example displays the following output: -// 1) The length of 'abcdefg' is 7 -// 2) The length of 'xyz' is 3 -// 3) The length of 'abcdefg' is 7 -// \ No newline at end of file diff --git a/snippets/csharp/VS_Snippets_CLR_System/System.String.Contains/cs/ContainsExt1.cs b/snippets/csharp/VS_Snippets_CLR_System/System.String.Contains/cs/ContainsExt1.cs index 09ea5f2f11c..a77eec8322e 100644 --- a/snippets/csharp/VS_Snippets_CLR_System/System.String.Contains/cs/ContainsExt1.cs +++ b/snippets/csharp/VS_Snippets_CLR_System/System.String.Contains/cs/ContainsExt1.cs @@ -6,42 +6,43 @@ public static class StringExtensions public static bool Contains(this String str, String substring, StringComparison comp) { - if (substring == null) - throw new ArgumentNullException("substring", + if (substring == null) + throw new ArgumentNullException("substring", "substring cannot be null."); - else if (! Enum.IsDefined(typeof(StringComparison), comp)) - throw new ArgumentException("comp is not a member of StringComparison", + else if (! Enum.IsDefined(typeof(StringComparison), comp)) + throw new ArgumentException("comp is not a member of StringComparison", "comp"); - return str.IndexOf(substring, comp) >= 0; + return str.IndexOf(substring, comp) >= 0; } } // namespace App { -// using System; public class Example { - public static void Main() - { - String s = "This is a string."; - String sub1 = "this"; - Console.WriteLine("Does '{0}' contain '{1}'?", s, sub1); - StringComparison comp = StringComparison.Ordinal; - Console.WriteLine(" {0:G}: {1}", comp, s.Contains(sub1, comp)); - - comp = StringComparison.OrdinalIgnoreCase; - Console.WriteLine(" {0:G}: {1}", comp, s.Contains(sub1, comp)); - } + public static void Main() + { + // + String s = "This is a string."; + String sub1 = "this"; + Console.WriteLine("Does '{0}' contain '{1}'?", s, sub1); + StringComparison comp = StringComparison.Ordinal; + Console.WriteLine(" {0:G}: {1}", comp, s.Contains(sub1, comp)); + + comp = StringComparison.OrdinalIgnoreCase; + Console.WriteLine(" {0:G}: {1}", comp, s.Contains(sub1, comp)); + + // The example displays the following output: + // Does 'This is a string.' contain 'this'? + // Ordinal: False + // OrdinalIgnoreCase: True + // + } } -// The example displays the following output: -// Does 'This is a string.' contain 'this'? -// Ordinal: False -// OrdinalIgnoreCase: True -// } diff --git a/snippets/csharp/VS_Snippets_CLR_System/System.String.Substring/cs/Substring1.cs b/snippets/csharp/VS_Snippets_CLR_System/System.String.Substring/cs/Substring1.cs index 7410a3d4afc..5c2247cb989 100644 --- a/snippets/csharp/VS_Snippets_CLR_System/System.String.Substring/cs/Substring1.cs +++ b/snippets/csharp/VS_Snippets_CLR_System/System.String.Substring/cs/Substring1.cs @@ -1,25 +1,26 @@ -// -using System; +using System; public class Example { - public static void Main() - { - String[] pairs = { "Color1=red", "Color2=green", "Color3=blue", + public static void Main() + { + // + String[] pairs = { "Color1=red", "Color2=green", "Color3=blue", "Title=Code Repository" }; - foreach (var pair in pairs) { - int position = pair.IndexOf("="); - if (position < 0) - continue; - Console.WriteLine("Key: {0}, Value: '{1}'", + foreach (var pair in pairs) { + int position = pair.IndexOf("="); + if (position < 0) + continue; + Console.WriteLine("Key: {0}, Value: '{1}'", pair.Substring(0, position), pair.Substring(position + 1)); - } - } + } + + // The example displays the following output: + // Key: Color1, Value: 'red' + // Key: Color2, Value: 'green' + // Key: Color3, Value: 'blue' + // Key: Title, Value: 'Code Repository' + // + } } -// The example displays the following output: -// Key: Color1, Value: 'red' -// Key: Color2, Value: 'green' -// Key: Color3, Value: 'blue' -// Key: Title, Value: 'Code Repository' -// diff --git a/snippets/csharp/VS_Snippets_CLR_System/System.String.Substring/cs/Substring10.cs b/snippets/csharp/VS_Snippets_CLR_System/System.String.Substring/cs/Substring10.cs index ccb8c2bc203..506c299b6a9 100644 --- a/snippets/csharp/VS_Snippets_CLR_System/System.String.Substring/cs/Substring10.cs +++ b/snippets/csharp/VS_Snippets_CLR_System/System.String.Substring/cs/Substring10.cs @@ -1,8 +1,10 @@ -// -using System; +using System; -public class SubStringTest { - public static void Main() { +public class SubStringTest +{ + public static void Main() + { + // string [] info = { "Name: Felica Walker", "Title: Mz.", "Age: 47", "Location: Paris", "Gender: F"}; int found = 0; @@ -12,24 +14,26 @@ public static void Main() { Console.WriteLine(s); Console.WriteLine("\nWe want to retrieve only the key information. That is:"); - foreach (string s in info) { + foreach (string s in info) + { found = s.IndexOf(": "); Console.WriteLine(" {0}", s.Substring(found + 2)); } + + // The example displays the following output: + // The initial values in the array are: + // Name: Felica Walker + // Title: Mz. + // Age: 47 + // Location: Paris + // Gender: F + // + // We want to retrieve only the key information. That is: + // Felica Walker + // Mz. + // 47 + // Paris + // F + // } } -// The example displays the following output: -// The initial values in the array are: -// Name: Felica Walker -// Title: Mz. -// Age: 47 -// Location: Paris -// Gender: F -// -// We want to retrieve only the key information. That is: -// Felica Walker -// Mz. -// 47 -// Paris -// F -// diff --git a/snippets/csharp/VS_Snippets_CLR_System/System.String.Substring/cs/Substring2.cs b/snippets/csharp/VS_Snippets_CLR_System/System.String.Substring/cs/Substring2.cs index 7d5d449d06a..acd79845e84 100644 --- a/snippets/csharp/VS_Snippets_CLR_System/System.String.Substring/cs/Substring2.cs +++ b/snippets/csharp/VS_Snippets_CLR_System/System.String.Substring/cs/Substring2.cs @@ -1,20 +1,21 @@ -// -using System; +using System; public class Example { - public static void Main() - { - String s = "aaaaabbbcccccccdd"; - Char charRange = 'b'; - int startIndex = s.IndexOf(charRange); - int endIndex = s.LastIndexOf(charRange); - int length = endIndex - startIndex + 1; - Console.WriteLine("{0}.Substring({1}, {2}) = {3}", + public static void Main() + { + // + String s = "aaaaabbbcccccccdd"; + Char charRange = 'b'; + int startIndex = s.IndexOf(charRange); + int endIndex = s.LastIndexOf(charRange); + int length = endIndex - startIndex + 1; + Console.WriteLine("{0}.Substring({1}, {2}) = {3}", s, startIndex, length, s.Substring(startIndex, length)); - } + + // The example displays the following output: + // aaaaabbbcccccccdd.Substring(5, 3) = bbb + // + } } -// The example displays the following output: -// aaaaabbbcccccccdd.Substring(5, 3) = bbb -// diff --git a/snippets/csharp/VS_Snippets_CLR_System/System.String.Substring/cs/Substring3.cs b/snippets/csharp/VS_Snippets_CLR_System/System.String.Substring/cs/Substring3.cs index 8fa96fef341..416aec100d2 100644 --- a/snippets/csharp/VS_Snippets_CLR_System/System.String.Substring/cs/Substring3.cs +++ b/snippets/csharp/VS_Snippets_CLR_System/System.String.Substring/cs/Substring3.cs @@ -1,21 +1,22 @@ -// -using System; +using System; public class Example { - public static void Main() - { - String s = "extantstill in existence"; - String searchString = ""; - int startIndex = s.IndexOf(searchString); - searchString = " + String s = "extantstill in existence"; + String searchString = ""; + int startIndex = s.IndexOf(searchString); + searchString = "extantstill in existence + // Substring; still in existence + // + } } -// The example displays the following output: -// Original string: extantstill in existence -// Substring; still in existence -// diff --git a/snippets/csharp/VS_Snippets_CLR_System/System.String.Substring/cs/Substring4.cs b/snippets/csharp/VS_Snippets_CLR_System/System.String.Substring/cs/Substring4.cs index 44e287b8763..2e53ac13007 100644 --- a/snippets/csharp/VS_Snippets_CLR_System/System.String.Substring/cs/Substring4.cs +++ b/snippets/csharp/VS_Snippets_CLR_System/System.String.Substring/cs/Substring4.cs @@ -1,18 +1,18 @@ -// -using System; +using System; public class Example { - public static void Main() - { - String value = "This is a string."; - int startIndex = 5; - int length = 2; - String substring = value.Substring(startIndex, length); - Console.WriteLine(substring); - } -} -// The example displays the following output: -// is -// + public static void Main() + { + // + String value = "This is a string."; + int startIndex = 5; + int length = 2; + String substring = value.Substring(startIndex, length); + Console.WriteLine(substring); + // The example displays the following output: + // is + // + } +} diff --git a/snippets/csharp/VS_Snippets_CLR_System/system.String.Compare/cs/Compare18.cs b/snippets/csharp/VS_Snippets_CLR_System/system.String.Compare/cs/Compare18.cs index 6dc02b42c68..7eb7813d38d 100644 --- a/snippets/csharp/VS_Snippets_CLR_System/system.String.Compare/cs/Compare18.cs +++ b/snippets/csharp/VS_Snippets_CLR_System/system.String.Compare/cs/Compare18.cs @@ -1,28 +1,28 @@ -// -using System; +using System; public class Example { - public static void Main() - { - String s1, s2; - - s1 = "car"; s2 = "Car"; - Console.WriteLine("'{0}' and '{1}': {2}", s1, s2, + public static void Main() + { + // + String s1, s2; + + s1 = "car"; s2 = "Car"; + Console.WriteLine("'{0}' and '{1}': {2}", s1, s2, String.Compare(s1, s2)); - s1 = "fork"; s2 = "forks"; - Console.WriteLine("'{0}' and '{1}': {2}", s1, s2, + s1 = "fork"; s2 = "forks"; + Console.WriteLine("'{0}' and '{1}': {2}", s1, s2, String.Compare(s1, s2)); - s1 = "mammal"; s2 = "fish"; - Console.WriteLine("'{0}' and '{1}': {2}", s1, s2, + s1 = "mammal"; s2 = "fish"; + Console.WriteLine("'{0}' and '{1}': {2}", s1, s2, String.Compare(s1, s2)); - } -} -// The example displays the following output: -// car' and 'Car': -1 -// fork' and 'forks': -1 -// mammal' and 'fish': 1 -// + // The example displays the following output: + // 'car' and 'Car': -1 + // 'fork' and 'forks': -1 + // 'mammal' and 'fish': 1 + // + } +} diff --git a/snippets/csharp/VS_Snippets_CLR_System/system.String.Compare/cs/Example.cs b/snippets/csharp/VS_Snippets_CLR_System/system.String.Compare/cs/Example.cs index 48cf8b49449..99771a651b6 100644 --- a/snippets/csharp/VS_Snippets_CLR_System/system.String.Compare/cs/Example.cs +++ b/snippets/csharp/VS_Snippets_CLR_System/system.String.Compare/cs/Example.cs @@ -1,57 +1,58 @@ -// -using System; +using System; using System.Globalization; public class Example { - public static void Main() - { - string string1 = "brother"; - string string2 = "Brother"; - string relation; - int result; - - // Cultural (linguistic) comparison. - result = String.Compare(string1, string2, new CultureInfo("en-US"), + public static void Main() + { + // + string string1 = "brother"; + string string2 = "Brother"; + string relation; + int result; + + // Cultural (linguistic) comparison. + result = String.Compare(string1, string2, new CultureInfo("en-US"), CompareOptions.None); - if (result > 0) - relation = "comes after"; - else if (result == 0) - relation = "is the same as"; - else - relation = "comes before"; + if (result > 0) + relation = "comes after"; + else if (result == 0) + relation = "is the same as"; + else + relation = "comes before"; - Console.WriteLine("'{0}' {1} '{2}'.", + Console.WriteLine("'{0}' {1} '{2}'.", string1, relation, string2); - // Cultural (linguistic) case-insensitive comparison. - result = String.Compare(string1, string2, new CultureInfo("en-US"), + // Cultural (linguistic) case-insensitive comparison. + result = String.Compare(string1, string2, new CultureInfo("en-US"), CompareOptions.IgnoreCase); - if (result > 0) - relation = "comes after"; - else if (result == 0) - relation = "is the same as"; - else - relation = "comes before"; + if (result > 0) + relation = "comes after"; + else if (result == 0) + relation = "is the same as"; + else + relation = "comes before"; - Console.WriteLine("'{0}' {1} '{2}'.", + Console.WriteLine("'{0}' {1} '{2}'.", string1, relation, string2); - // Culture-insensitive ordinal comparison. - result = String.CompareOrdinal(string1, string2); - if (result > 0) - relation = "comes after"; - else if (result == 0) - relation = "is the same as"; - else - relation = "comes before"; + // Culture-insensitive ordinal comparison. + result = String.CompareOrdinal(string1, string2); + if (result > 0) + relation = "comes after"; + else if (result == 0) + relation = "is the same as"; + else + relation = "comes before"; - Console.WriteLine("'{0}' {1} '{2}'.", + Console.WriteLine("'{0}' {1} '{2}'.", string1, relation, string2); - } + + // The example produces the following output: + // 'brother' comes before 'Brother'. + // 'brother' is the same as 'Brother'. + // 'brother' comes after 'Brother'. + // + } } -// The example produces the following output: -// 'brother' comes before 'Brother'. -// 'brother' is the same as 'Brother'. -// 'brother' comes after 'Brother'. -// diff --git a/snippets/csharp/VS_Snippets_CLR_System/system.String.Compare/cs/compare02.cs b/snippets/csharp/VS_Snippets_CLR_System/system.String.Compare/cs/compare02.cs index 91c68f4dea5..d9335e5a87d 100644 --- a/snippets/csharp/VS_Snippets_CLR_System/system.String.Compare/cs/compare02.cs +++ b/snippets/csharp/VS_Snippets_CLR_System/system.String.Compare/cs/compare02.cs @@ -1,35 +1,34 @@ -// -using System; +using System; class Example { - static void Main() - { - // Create upper-case characters from their Unicode code units. - String stringUpper = "\x0041\x0042\x0043"; + static void Main() + { + // + // Create upper-case characters from their Unicode code units. + String stringUpper = "\x0041\x0042\x0043"; - // Create lower-case characters from their Unicode code units. - String stringLower = "\x0061\x0062\x0063"; + // Create lower-case characters from their Unicode code units. + String stringLower = "\x0061\x0062\x0063"; - // Display the strings. - Console.WriteLine("Comparing '{0}' and '{1}':", + // Display the strings. + Console.WriteLine("Comparing '{0}' and '{1}':", stringUpper, stringLower); - // Compare the uppercased strings; the result is true. - Console.WriteLine("The Strings are equal when capitalized? {0}", + // Compare the uppercased strings; the result is true. + Console.WriteLine("The Strings are equal when capitalized? {0}", String.Compare(stringUpper.ToUpper(), stringLower.ToUpper()) == 0 ? "true" : "false"); - // The previous method call is equivalent to this Compare method, which ignores case. - Console.WriteLine("The Strings are equal when case is ignored? {0}", + // The previous method call is equivalent to this Compare method, which ignores case. + Console.WriteLine("The Strings are equal when case is ignored? {0}", String.Compare(stringUpper, stringLower, true) == 0 ? "true" : "false" ); - } -} -// The example displays the following output: -// Comparing 'ABC' and 'abc': -// The Strings are equal when capitalized? true -// The Strings are equal when case is ignored? true -// - + // The example displays the following output: + // Comparing 'ABC' and 'abc': + // The Strings are equal when capitalized? true + // The Strings are equal when case is ignored? true + // + } +} diff --git a/snippets/csharp/VS_Snippets_CLR_System/system.String.Compare/cs/compare21.cs b/snippets/csharp/VS_Snippets_CLR_System/system.String.Compare/cs/compare21.cs index a2579e81d15..d77d9562534 100644 --- a/snippets/csharp/VS_Snippets_CLR_System/system.String.Compare/cs/compare21.cs +++ b/snippets/csharp/VS_Snippets_CLR_System/system.String.Compare/cs/compare21.cs @@ -3,16 +3,16 @@ public class Example { - public static void Main() - { - string s1 = "ani\u00ADmal"; - string s2 = "animal"; - - Console.WriteLine("Comparison of '{0}' and '{1}': {2}", + public static void Main() + { + string s1 = "ani\u00ADmal"; + string s2 = "animal"; + + Console.WriteLine("Comparison of '{0}' and '{1}': {2}", s1, s2, String.Compare(s1, s2)); - } + + // The example displays the following output: + // Comparison of 'ani-mal' and 'animal': 0 + } } -// The example displays the following output: -// Comparison of 'ani-mal' and 'animal': 0 // - diff --git a/snippets/csharp/VS_Snippets_CLR_System/system.String.Compare/cs/compare22.cs b/snippets/csharp/VS_Snippets_CLR_System/system.String.Compare/cs/compare22.cs index da320a7eb3e..d5dbe4ab31c 100644 --- a/snippets/csharp/VS_Snippets_CLR_System/system.String.Compare/cs/compare22.cs +++ b/snippets/csharp/VS_Snippets_CLR_System/system.String.Compare/cs/compare22.cs @@ -3,16 +3,16 @@ public class Example { - public static void Main() - { - string s1 = "Ani\u00ADmal"; - string s2 = "animal"; + public static void Main() + { + string s1 = "Ani\u00ADmal"; + string s2 = "animal"; - Console.WriteLine("Comparison of '{0}' and '{1}': {2}", + Console.WriteLine("Comparison of '{0}' and '{1}': {2}", s1, s2, String.Compare(s1, s2, true)); - } + + // The example displays the following output: + // Comparison of 'Ani-mal' and 'animal': 0 + } } -// The example displays the following output: -// Comparison of 'ani-mal' and 'animal': 0 // - diff --git a/snippets/csharp/VS_Snippets_CLR_System/system.String.Compare/cs/compare23.cs b/snippets/csharp/VS_Snippets_CLR_System/system.String.Compare/cs/compare23.cs index 9733b3a2d60..84a622f0589 100644 --- a/snippets/csharp/VS_Snippets_CLR_System/system.String.Compare/cs/compare23.cs +++ b/snippets/csharp/VS_Snippets_CLR_System/system.String.Compare/cs/compare23.cs @@ -4,17 +4,17 @@ public class Example { - public static void Main() - { - string s1 = "Ani\u00ADmal"; - string s2 = "animal"; + public static void Main() + { + string s1 = "Ani\u00ADmal"; + string s2 = "animal"; - Console.WriteLine("Comparison of '{0}' and '{1}': {2}", + Console.WriteLine("Comparison of '{0}' and '{1}': {2}", s1, s2, String.Compare(s1, s2, true, CultureInfo.InvariantCulture)); - } + + // The example displays the following output: + // Comparison of 'Ani-mal' and 'animal': 0 + } } -// The example displays the following output: -// Comparison of 'ani-mal' and 'animal': 0 // - diff --git a/snippets/csharp/VS_Snippets_CLR_System/system.String.IndexOf/CS/ignorable21.cs b/snippets/csharp/VS_Snippets_CLR_System/system.String.IndexOf/CS/ignorable21.cs index 6454cf6eefe..36e0ee1abab 100644 --- a/snippets/csharp/VS_Snippets_CLR_System/system.String.IndexOf/CS/ignorable21.cs +++ b/snippets/csharp/VS_Snippets_CLR_System/system.String.IndexOf/CS/ignorable21.cs @@ -3,31 +3,31 @@ public class Example { - public static void Main() - { - string s1 = "ani\u00ADmal"; - string s2 = "animal"; + public static void Main() + { + string s1 = "ani\u00ADmal"; + string s2 = "animal"; - // Find the index of the soft hyphen. - Console.WriteLine(s1.IndexOf("\u00AD")); - Console.WriteLine(s2.IndexOf("\u00AD")); + // Find the index of the soft hyphen. + Console.WriteLine(s1.IndexOf("\u00AD")); + Console.WriteLine(s2.IndexOf("\u00AD")); - // Find the index of the soft hyphen followed by "n". - Console.WriteLine(s1.IndexOf("\u00ADn")); - Console.WriteLine(s2.IndexOf("\u00ADn")); + // Find the index of the soft hyphen followed by "n". + Console.WriteLine(s1.IndexOf("\u00ADn")); + Console.WriteLine(s2.IndexOf("\u00ADn")); - // Find the index of the soft hyphen followed by "m". - Console.WriteLine(s1.IndexOf("\u00ADm")); - Console.WriteLine(s2.IndexOf("\u00ADm")); - } + // Find the index of the soft hyphen followed by "m". + Console.WriteLine(s1.IndexOf("\u00ADm")); + Console.WriteLine(s2.IndexOf("\u00ADm")); + + // The example displays the following output + // if run under the .NET Framework 4 or later: + // 0 + // 0 + // 1 + // 1 + // 4 + // 3 + } } -// The example displays the following output -// if run under the .NET Framework 4 or later: -// 0 -// 0 -// 1 -// 1 -// 4 -// 3 // - diff --git a/snippets/csharp/VS_Snippets_CLR_System/system.String.IndexOf/CS/ignorable22.cs b/snippets/csharp/VS_Snippets_CLR_System/system.String.IndexOf/CS/ignorable22.cs index 3c963c14dd6..e1180339da9 100644 --- a/snippets/csharp/VS_Snippets_CLR_System/system.String.IndexOf/CS/ignorable22.cs +++ b/snippets/csharp/VS_Snippets_CLR_System/system.String.IndexOf/CS/ignorable22.cs @@ -3,17 +3,18 @@ public class Example { - public static void Main() - { - string searchString = "\u00ADm"; - string s1 = "ani\u00ADmal" ; - string s2 = "animal"; + public static void Main() + { + string searchString = "\u00ADm"; + string s1 = "ani\u00ADmal" ; + string s2 = "animal"; - Console.WriteLine(s1.IndexOf(searchString, 2)); - Console.WriteLine(s2.IndexOf(searchString, 2)); - } + Console.WriteLine(s1.IndexOf(searchString, 2)); + Console.WriteLine(s2.IndexOf(searchString, 2)); + + // The example displays the following output: + // 4 + // 3 + } } -// The example displays the following output: -// 4 -// 3 // diff --git a/snippets/csharp/VS_Snippets_CLR_System/system.String.IndexOf/CS/ignorable23.cs b/snippets/csharp/VS_Snippets_CLR_System/system.String.IndexOf/CS/ignorable23.cs index 7614d1a0895..be4b57bf6f2 100644 --- a/snippets/csharp/VS_Snippets_CLR_System/system.String.IndexOf/CS/ignorable23.cs +++ b/snippets/csharp/VS_Snippets_CLR_System/system.String.IndexOf/CS/ignorable23.cs @@ -3,17 +3,18 @@ public class Example { - public static void Main() - { - string searchString = "\u00ADm"; - string s1 = "ani\u00ADmal" ; - string s2 = "animal"; + public static void Main() + { + string searchString = "\u00ADm"; + string s1 = "ani\u00ADmal" ; + string s2 = "animal"; - Console.WriteLine(s1.IndexOf(searchString, 2, 4)); - Console.WriteLine(s2.IndexOf(searchString, 2, 4)); - } + Console.WriteLine(s1.IndexOf(searchString, 2, 4)); + Console.WriteLine(s2.IndexOf(searchString, 2, 4)); + + // The example displays the following output: + // 4 + // 3 + } } -// The example displays the following output: -// 4 -// 3 // diff --git a/snippets/csharp/VS_Snippets_CLR_System/system.String.IndexOf/CS/ignorable24.cs b/snippets/csharp/VS_Snippets_CLR_System/system.String.IndexOf/CS/ignorable24.cs index ff6323f429b..c63cb7df854 100644 --- a/snippets/csharp/VS_Snippets_CLR_System/system.String.IndexOf/CS/ignorable24.cs +++ b/snippets/csharp/VS_Snippets_CLR_System/system.String.IndexOf/CS/ignorable24.cs @@ -3,21 +3,23 @@ public class Example { - public static void Main() - { - string searchString = "\u00ADm"; - string s1 = "ani\u00ADmal" ; - string s2 = "animal"; + public static void Main() + { - Console.WriteLine(s1.IndexOf(searchString, 2, 4, StringComparison.CurrentCulture)); - Console.WriteLine(s1.IndexOf(searchString, 2, 4, StringComparison.Ordinal)); - Console.WriteLine(s2.IndexOf(searchString, 2, 4, StringComparison.CurrentCulture)); - Console.WriteLine(s2.IndexOf(searchString, 2, 4, StringComparison.Ordinal)); - } + string searchString = "\u00ADm"; + string s1 = "ani\u00ADmal" ; + string s2 = "animal"; + + Console.WriteLine(s1.IndexOf(searchString, 2, 4, StringComparison.CurrentCulture)); + Console.WriteLine(s1.IndexOf(searchString, 2, 4, StringComparison.Ordinal)); + Console.WriteLine(s2.IndexOf(searchString, 2, 4, StringComparison.CurrentCulture)); + Console.WriteLine(s2.IndexOf(searchString, 2, 4, StringComparison.Ordinal)); + + // The example displays the following output: + // 4 + // 3 + // 3 + // -1 + } } -// The example displays the following output: -// 4 -// 3 -// 3 -// -1 // diff --git a/snippets/csharp/VS_Snippets_CLR_System/system.String.IndexOf/CS/ignorable25.cs b/snippets/csharp/VS_Snippets_CLR_System/system.String.IndexOf/CS/ignorable25.cs index ddf7066bce8..b5d9fafe11a 100644 --- a/snippets/csharp/VS_Snippets_CLR_System/system.String.IndexOf/CS/ignorable25.cs +++ b/snippets/csharp/VS_Snippets_CLR_System/system.String.IndexOf/CS/ignorable25.cs @@ -3,21 +3,23 @@ public class Example { - public static void Main() - { - string searchString = "\u00ADm"; - string s1 = "ani\u00ADmal" ; - string s2 = "animal"; + public static void Main() + { + + string searchString = "\u00ADm"; + string s1 = "ani\u00ADmal" ; + string s2 = "animal"; - Console.WriteLine(s1.IndexOf(searchString, 2, StringComparison.CurrentCulture)); - Console.WriteLine(s1.IndexOf(searchString, 2, StringComparison.Ordinal)); - Console.WriteLine(s2.IndexOf(searchString, 2, StringComparison.CurrentCulture)); - Console.WriteLine(s2.IndexOf(searchString, 2, StringComparison.Ordinal)); - } + Console.WriteLine(s1.IndexOf(searchString, 2, StringComparison.CurrentCulture)); + Console.WriteLine(s1.IndexOf(searchString, 2, StringComparison.Ordinal)); + Console.WriteLine(s2.IndexOf(searchString, 2, StringComparison.CurrentCulture)); + Console.WriteLine(s2.IndexOf(searchString, 2, StringComparison.Ordinal)); + + // The example displays the following output: + // 4 + // 3 + // 3 + // -1 + } } -// The example displays the following output: -// 4 -// 3 -// 3 -// -1 // diff --git a/snippets/csharp/VS_Snippets_CLR_System/system.String.IndexOf/CS/ignorable26.cs b/snippets/csharp/VS_Snippets_CLR_System/system.String.IndexOf/CS/ignorable26.cs index 1dcf77b0177..61944637145 100644 --- a/snippets/csharp/VS_Snippets_CLR_System/system.String.IndexOf/CS/ignorable26.cs +++ b/snippets/csharp/VS_Snippets_CLR_System/system.String.IndexOf/CS/ignorable26.cs @@ -3,52 +3,52 @@ public class Example { - public static void Main() - { - string s1 = "ani\u00ADmal"; - string s2 = "animal"; + public static void Main() + { + string s1 = "ani\u00ADmal"; + string s2 = "animal"; - Console.WriteLine("Culture-sensitive comparison:"); - // Use culture-sensitive comparison to find the soft hyphen. - Console.WriteLine(s1.IndexOf("\u00AD", StringComparison.CurrentCulture)); - Console.WriteLine(s2.IndexOf("\u00AD", StringComparison.CurrentCulture)); + Console.WriteLine("Culture-sensitive comparison:"); + // Use culture-sensitive comparison to find the soft hyphen. + Console.WriteLine(s1.IndexOf("\u00AD", StringComparison.CurrentCulture)); + Console.WriteLine(s2.IndexOf("\u00AD", StringComparison.CurrentCulture)); - // Use culture-sensitive comparison to find the soft hyphen followed by "n". - Console.WriteLine(s1.IndexOf("\u00ADn", StringComparison.CurrentCulture)); - Console.WriteLine(s2.IndexOf("\u00ADn", StringComparison.CurrentCulture)); + // Use culture-sensitive comparison to find the soft hyphen followed by "n". + Console.WriteLine(s1.IndexOf("\u00ADn", StringComparison.CurrentCulture)); + Console.WriteLine(s2.IndexOf("\u00ADn", StringComparison.CurrentCulture)); - // Use culture-sensitive comparison to find the soft hyphen followed by "m". - Console.WriteLine(s1.IndexOf("\u00ADm", StringComparison.CurrentCulture)); - Console.WriteLine(s2.IndexOf("\u00ADm", StringComparison.CurrentCulture)); + // Use culture-sensitive comparison to find the soft hyphen followed by "m". + Console.WriteLine(s1.IndexOf("\u00ADm", StringComparison.CurrentCulture)); + Console.WriteLine(s2.IndexOf("\u00ADm", StringComparison.CurrentCulture)); - Console.WriteLine("Ordinal comparison:"); - // Use ordinal comparison to find the soft hyphen. - Console.WriteLine(s1.IndexOf("\u00AD", StringComparison.Ordinal)); - Console.WriteLine(s2.IndexOf("\u00AD", StringComparison.Ordinal)); + Console.WriteLine("Ordinal comparison:"); + // Use ordinal comparison to find the soft hyphen. + Console.WriteLine(s1.IndexOf("\u00AD", StringComparison.Ordinal)); + Console.WriteLine(s2.IndexOf("\u00AD", StringComparison.Ordinal)); - // Use ordinal comparison to find the soft hyphen followed by "n". - Console.WriteLine(s1.IndexOf("\u00ADn", StringComparison.Ordinal)); - Console.WriteLine(s2.IndexOf("\u00ADn", StringComparison.Ordinal)); + // Use ordinal comparison to find the soft hyphen followed by "n". + Console.WriteLine(s1.IndexOf("\u00ADn", StringComparison.Ordinal)); + Console.WriteLine(s2.IndexOf("\u00ADn", StringComparison.Ordinal)); - // Use ordinal comparison to find the soft hyphen followed by "m". - Console.WriteLine(s1.IndexOf("\u00ADm", StringComparison.Ordinal)); - Console.WriteLine(s2.IndexOf("\u00ADm", StringComparison.Ordinal)); - } + // Use ordinal comparison to find the soft hyphen followed by "m". + Console.WriteLine(s1.IndexOf("\u00ADm", StringComparison.Ordinal)); + Console.WriteLine(s2.IndexOf("\u00ADm", StringComparison.Ordinal)); + + // The example displays the following output: + // Culture-sensitive comparison: + // 0 + // 0 + // 1 + // 1 + // 4 + // 3 + // Ordinal comparison: + // 3 + // -1 + // -1 + // -1 + // 3 + // -1 + } } -// The example displays the following output: -// Culture-sensitive comparison: -// 0 -// 0 -// 1 -// 1 -// 4 -// 3 -// Ordinal comparison: -// 3 -// -1 -// -1 -// -1 -// 3 -// -1 // - diff --git a/snippets/csharp/VS_Snippets_CLR_System/system.String.IndexOf/CS/indexof_c.cs b/snippets/csharp/VS_Snippets_CLR_System/system.String.IndexOf/CS/indexof_c.cs index 1e470fca668..2b7c273d005 100644 --- a/snippets/csharp/VS_Snippets_CLR_System/system.String.IndexOf/CS/indexof_c.cs +++ b/snippets/csharp/VS_Snippets_CLR_System/system.String.IndexOf/CS/indexof_c.cs @@ -1,36 +1,36 @@ -// -using System; +using System; class Example { - static void Main() - { - // Create a Unicode string with 5 Greek Alpha characters. - String szGreekAlpha = new String('\u0391',5); + static void Main() + { + // + // Create a Unicode string with 5 Greek Alpha characters. + String szGreekAlpha = new String('\u0391',5); - // Create a Unicode string with 3 Greek Omega characters. - String szGreekOmega = "\u03A9\u03A9\u03A9"; - - String szGreekLetters = String.Concat(szGreekOmega, szGreekAlpha, + // Create a Unicode string with 3 Greek Omega characters. + String szGreekOmega = "\u03A9\u03A9\u03A9"; + + String szGreekLetters = String.Concat(szGreekOmega, szGreekAlpha, szGreekOmega.Clone()); - // Display the entire string. - Console.WriteLine("The string: {0}", szGreekLetters); + // Display the entire string. + Console.WriteLine("The string: {0}", szGreekLetters); - // The first index of Alpha. - int ialpha = szGreekLetters.IndexOf('\u0391'); - // The first index of Omega. - int iomega = szGreekLetters.IndexOf('\u03A9'); + // The first index of Alpha. + int ialpha = szGreekLetters.IndexOf('\u0391'); + // The first index of Omega. + int iomega = szGreekLetters.IndexOf('\u03A9'); - Console.WriteLine("First occurrence of the Greek letter Alpha: Index {0}", + Console.WriteLine("First occurrence of the Greek letter Alpha: Index {0}", ialpha); - Console.WriteLine("First occurrence of the Greek letter Omega: Index {0}", + Console.WriteLine("First occurrence of the Greek letter Omega: Index {0}", iomega); - } -} -// The example displays the following output: -// The string: OOO?????OOO -// First occurrence of the Greek letter Alpha: Index 3 -// First occurrence of the Greek letter Omega: Index 0 -// + // The example displays the following output: + // The string: ΩΩΩΑΑΑΑΑΩΩΩ + // First occurrence of the Greek letter Alpha: Index 3 + // First occurrence of the Greek letter Omega: Index 0 + // + } +} diff --git a/snippets/csharp/VS_Snippets_CLR_System/system.String.IndexOf/CS/simple1.cs b/snippets/csharp/VS_Snippets_CLR_System/system.String.IndexOf/CS/simple1.cs index cb2b1016a59..f95f43a3db8 100644 --- a/snippets/csharp/VS_Snippets_CLR_System/system.String.IndexOf/CS/simple1.cs +++ b/snippets/csharp/VS_Snippets_CLR_System/system.String.IndexOf/CS/simple1.cs @@ -1,17 +1,18 @@ -// -using System; +using System; public class Example { - public static void Main() - { - String str = "animal"; - String toFind = "n"; - int index = str.IndexOf("n"); - Console.WriteLine("Found '{0}' in '{1}' at position {2}", + public static void Main() + { + // + String str = "animal"; + String toFind = "n"; + int index = str.IndexOf("n"); + Console.WriteLine("Found '{0}' in '{1}' at position {2}", toFind, str, index); - } + + // The example displays the following output: + // Found 'n' in 'animal' at position 1 + // + } } -// The example displays the following output: -// Found 'n' in 'animal' at position 1 -// \ No newline at end of file diff --git a/snippets/csharp/VS_Snippets_CLR_System/system.String.Trim/cs/Trim1.cs b/snippets/csharp/VS_Snippets_CLR_System/system.String.Trim/cs/Trim1.cs index 8c543e0955f..d6d9624dde9 100644 --- a/snippets/csharp/VS_Snippets_CLR_System/system.String.Trim/cs/Trim1.cs +++ b/snippets/csharp/VS_Snippets_CLR_System/system.String.Trim/cs/Trim1.cs @@ -1,19 +1,20 @@ -// -using System; +using System; public class Example { - public static void Main() - { - char[] charsToTrim = { '*', ' ', '\''}; - string banner = "*** Much Ado About Nothing ***"; - string result = banner.Trim(charsToTrim); - Console.WriteLine("Trimmmed\n {0}\nto\n '{1}'", banner, result); - } + public static void Main() + { + // + char[] charsToTrim = { '*', ' ', '\''}; + string banner = "*** Much Ado About Nothing ***"; + string result = banner.Trim(charsToTrim); + Console.WriteLine("Trimmmed\n {0}\nto\n '{1}'", banner, result); + + // The example displays the following output: + // Trimmmed + // *** Much Ado About Nothing *** + // to + // 'Much Ado About Nothing' + // + } } -// The example displays the following output: -// Trimmmed -// *** Much Ado About Nothing *** -// to -// 'Much Ado About Nothing' -// diff --git a/snippets/csharp/VS_Snippets_CLR_System/system.String.Trim/cs/Trim2.cs b/snippets/csharp/VS_Snippets_CLR_System/system.String.Trim/cs/Trim2.cs index ffcdb751800..61df41a1f9f 100644 --- a/snippets/csharp/VS_Snippets_CLR_System/system.String.Trim/cs/Trim2.cs +++ b/snippets/csharp/VS_Snippets_CLR_System/system.String.Trim/cs/Trim2.cs @@ -1,33 +1,34 @@ -// -using System; +using System; public class Example { - public static void Main() - { - Console.Write("Enter your first name: "); - string firstName = Console.ReadLine(); + public static void Main() + { + // + Console.Write("Enter your first name: "); + string firstName = Console.ReadLine(); - Console.Write("Enter your middle name or initial: "); - string middleName = Console.ReadLine(); + Console.Write("Enter your middle name or initial: "); + string middleName = Console.ReadLine(); - Console.Write("Enter your last name: "); - string lastName = Console.ReadLine(); + Console.Write("Enter your last name: "); + string lastName = Console.ReadLine(); - Console.WriteLine(); - Console.WriteLine("You entered '{0}', '{1}', and '{2}'.", + Console.WriteLine(); + Console.WriteLine("You entered '{0}', '{1}', and '{2}'.", firstName, middleName, lastName); - string name = ((firstName.Trim() + " " + middleName.Trim()).Trim() + " " + + string name = ((firstName.Trim() + " " + middleName.Trim()).Trim() + " " + lastName.Trim()).Trim(); - Console.WriteLine("The result is " + name + "."); - } + Console.WriteLine("The result is " + name + "."); + + // The following is a possible output from this example: + // Enter your first name: John + // Enter your middle name or initial: + // Enter your last name: Doe + // + // You entered ' John ', '', and ' Doe'. + // The result is John Doe. + // + } } -// The following is possible output from this example: -// Enter your first name: John -// Enter your middle name or initial: -// Enter your last name: Doe -// -// You entered ' John ', '', and ' Doe'. -// The result is John Doe. -// diff --git a/snippets/csharp/VS_Snippets_CLR_System/system.string.isnullorempty/cs/NullString1.cs b/snippets/csharp/VS_Snippets_CLR_System/system.string.isnullorempty/cs/NullString1.cs index 85b46b508a3..cbeb40830a9 100644 --- a/snippets/csharp/VS_Snippets_CLR_System/system.string.isnullorempty/cs/NullString1.cs +++ b/snippets/csharp/VS_Snippets_CLR_System/system.string.isnullorempty/cs/NullString1.cs @@ -1,37 +1,40 @@ -// -using System; +using System; public class Example { - public static void Main() - { - String s = null; + public static void Main() + { + // + String s = null; - Console.WriteLine("The value of the string is '{0}'", s); + Console.WriteLine("The value of the string is '{0}'", s); - try { - Console.WriteLine("String length is {0}", s.Length); - } - catch (NullReferenceException e) { - Console.WriteLine(e.Message); - } - } + try + { + Console.WriteLine("String length is {0}", s.Length); + } + catch (NullReferenceException e) + { + Console.WriteLine(e.Message); + } + + // The example displays the following output: + // The value of the string is '' + // Object reference not set to an instance of an object. + // + } } -// The example displays the following output: -// The value of the string is '' -// Object reference not set to an instance of an object. -// public class Empty { - public void Test() - { - // - String s = ""; - Console.WriteLine("The length of '{0}' is {1}.", s, s.Length); - // The example displays the following output: - // The length of '' is 0. - // - } -} + public void Test() + { + // + String s = ""; + Console.WriteLine("The length of '{0}' is {1}.", s, s.Length); + // The example displays the following output: + // The length of '' is 0. + // + } +} diff --git a/snippets/csharp/VS_Snippets_CLR_System/system.string.replace/cs/replace1.cs b/snippets/csharp/VS_Snippets_CLR_System/system.string.replace/cs/replace1.cs index ef843f9af85..847d347b7d1 100644 --- a/snippets/csharp/VS_Snippets_CLR_System/system.string.replace/cs/replace1.cs +++ b/snippets/csharp/VS_Snippets_CLR_System/system.string.replace/cs/replace1.cs @@ -1,17 +1,18 @@ -// -using System; +using System; public class Example { - public static void Main() - { - String s = "aaa"; - Console.WriteLine("The initial string: '{0}'", s); - s = s.Replace("a", "b").Replace("b", "c").Replace("c", "d"); - Console.WriteLine("The final string: '{0}'", s); - } + public static void Main() + { + // + String s = "aaa"; + Console.WriteLine("The initial string: '{0}'", s); + s = s.Replace("a", "b").Replace("b", "c").Replace("c", "d"); + Console.WriteLine("The final string: '{0}'", s); + + // The example displays the following output: + // The initial string: 'aaa' + // The final string: 'ddd' + // + } } -// The example displays the following output: -// The initial string: 'aaa' -// The final string: 'ddd' -// diff --git a/snippets/csharp/VS_Snippets_CLR_System/system.string.replace/cs/replace2.cs b/snippets/csharp/VS_Snippets_CLR_System/system.string.replace/cs/replace2.cs index bd1e03510e3..e7f77c54ca9 100644 --- a/snippets/csharp/VS_Snippets_CLR_System/system.string.replace/cs/replace2.cs +++ b/snippets/csharp/VS_Snippets_CLR_System/system.string.replace/cs/replace2.cs @@ -1,17 +1,18 @@ -// -using System; +using System; public class Example { - public static void Main() - { - String s = new String('a', 3); - Console.WriteLine("The initial string: '{0}'", s); - s = s.Replace('a', 'b').Replace('b', 'c').Replace('c', 'd'); - Console.WriteLine("The final string: '{0}'", s); - } + public static void Main() + { + // + String s = new String('a', 3); + Console.WriteLine("The initial string: '{0}'", s); + s = s.Replace('a', 'b').Replace('b', 'c').Replace('c', 'd'); + Console.WriteLine("The final string: '{0}'", s); + + // The example displays the following output: + // The initial string: 'aaa' + // The final string: 'ddd' + // + } } -// The example displays the following output: -// The initial string: 'aaa' -// The final string: 'ddd' -//