Skip to content

Is it a useful change, to replace built-in types with keywords? #6917

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Aug 4, 2021
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
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

public static class StringLibrary
{
public static int SubstringStartsAt(String fullString, String substr)
public static int SubstringStartsAt(string fullString, string substr)
{
return fullString.IndexOf(substr, StringComparison.Ordinal);
}
Expand All @@ -22,8 +22,8 @@ public class Example
{
public static void Main()
{
String value = "The archaeologist";
String substring = "archæ";
string value = "The archaeologist";
string substring = "archæ";
int position = StringLibrary.SubstringStartsAt(value, substring);
if (position >= 0)
Console.WriteLine("'{0}' found in '{1}' starting at position {2}",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

public static class StringLibrary
{
public static int SubstringStartsAt(String fullString, String substr)
public static int SubstringStartsAt(string fullString, string substr)
{
return fullString.IndexOf(substr, StringComparison.CurrentCulture);
}
Expand All @@ -22,8 +22,8 @@ public class Example
{
public static void Main()
{
String value = "The archaeologist";
String substring = "archæ";
string value = "The archaeologist";
string substring = "archæ";
int position = StringLibrary.SubstringStartsAt(value, substring);
if (position >= 0)
Console.WriteLine("'{0}' found in '{1}' starting at position {2}",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

public static class StringLibrary
{
public static int SubstringStartsAt(String fullString, String substr)
public static int SubstringStartsAt(string fullString, string substr)
{
bool flag;
if (AppContext.TryGetSwitch("StringLibrary.DoNotUseCultureSensitiveComparison", out flag) && flag == true)
Expand All @@ -26,8 +26,8 @@ public class Example
{
public static void Main()
{
String value = "The archaeologist";
String substring = "archæ";
string value = "The archaeologist";
string substring = "archæ";
int position = StringLibrary.SubstringStartsAt(value, substring);
if (position >= 0)
Console.WriteLine("'{0}' found in '{1}' starting at position {2}",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

public class Example
{
private const String SettingName = "AppContextSwitchOverrides";
private const String SwitchName = "Switch.Application.Utilities.SwitchName";
private const string SettingName = "AppContextSwitchOverrides";
private const string SwitchName = "Switch.Application.Utilities.SwitchName";

public static void Main()
{
Expand All @@ -22,8 +22,8 @@ public static void Main()

ConfigurationSection sec = config.GetSection("runtime");
if (sec != null) {
String rawXml = sec.SectionInformation.GetRawXml();
if (String.IsNullOrEmpty(rawXml)) return;
string rawXml = sec.SectionInformation.GetRawXml();
if (string.IsNullOrEmpty(rawXml)) return;

var doc = new XmlDocument();
doc.LoadXml(rawXml);
Expand All @@ -34,11 +34,11 @@ public static void Main()
if (node.Name.Equals(SettingName, StringComparison.Ordinal)) {
// Get attribute value
XmlAttribute attr = node.Attributes["value"];
String[] nameValuePair = attr.Value.Split('=');
string[] nameValuePair = attr.Value.Split('=');
// Determine whether the switch we want is present.
if (SwitchName.Equals(nameValuePair[0], StringComparison.Ordinal)) {
bool tempFlag = false;
if (Boolean.TryParse(CultureInfo.InvariantCulture.TextInfo.ToTitleCase(nameValuePair[1]),
if (bool.TryParse(CultureInfo.InvariantCulture.TextInfo.ToTitleCase(nameValuePair[1]),
out tempFlag))
AppContext.SetSwitch(nameValuePair[0], tempFlag);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class Program
static void Main()
{
//<snippet01>
List<String> names = new List<String>();
List<string> names = new List<string>();
names.Add("Bruce");
names.Add("Alfred");
names.Add("Tim");
Expand All @@ -17,7 +17,7 @@ static void Main()

// The following demonstrates the anonymous method feature of C#
// to display the contents of the list to the console.
names.ForEach(delegate(String name)
names.ForEach(delegate(string name)
{
Console.WriteLine(name);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public static void Main()
Action<string[], string[], int> copyOperation = CopyStrings;
copyOperation(ordinals, copiedOrdinals, 3);
foreach (string ordinal in copiedOrdinals)
Console.WriteLine(String.IsNullOrEmpty(ordinal) ? "<None>" : ordinal);
Console.WriteLine(string.IsNullOrEmpty(ordinal) ? "<None>" : ordinal);
}

private static void CopyStrings(string[] source, string[] target, int startPos)
Expand All @@ -19,7 +19,7 @@ private static void CopyStrings(string[] source, string[] target, int startPos)
throw new IndexOutOfRangeException("The source and target arrays must have the same number of elements.");

for (int ctr = startPos; ctr <= source.Length - 1; ctr++)
target[ctr] = String.Copy(source[ctr]);
target[ctr] = string.Copy(source[ctr]);
}
}
// </Snippet2>
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public static void Main()
{ CopyStrings(s1, s2, pos); };
copyOperation(ordinals, copiedOrdinals, 3);
foreach (string ordinal in copiedOrdinals)
Console.WriteLine(String.IsNullOrEmpty(ordinal) ? "<None>" : ordinal);
Console.WriteLine(string.IsNullOrEmpty(ordinal) ? "<None>" : ordinal);
}

private static void CopyStrings(string[] source, string[] target, int startPos)
Expand All @@ -22,7 +22,7 @@ private static void CopyStrings(string[] source, string[] target, int startPos)
throw new IndexOutOfRangeException("The source and target arrays must have the same number of elements.");

for (int ctr = startPos; ctr <= source.Length - 1; ctr++)
target[ctr] = String.Copy(source[ctr]);
target[ctr] = string.Copy(source[ctr]);
}
}
// </Snippet3>
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public static void Main()
StringCopy copyOperation = CopyStrings;
copyOperation(ordinals, copiedOrdinals, 3);
foreach (string ordinal in copiedOrdinals)
Console.WriteLine(String.IsNullOrEmpty(ordinal) ? "<None>" : ordinal);
Console.WriteLine(string.IsNullOrEmpty(ordinal) ? "<None>" : ordinal);
}

private static void CopyStrings(string[] source, string[] target, int startPos)
Expand All @@ -23,7 +23,7 @@ private static void CopyStrings(string[] source, string[] target, int startPos)
throw new IndexOutOfRangeException("The source and target arrays must have the same number of elements.");

for (int ctr = startPos; ctr <= source.Length - 1; ctr++)
target[ctr] = String.Copy(source[ctr]);
target[ctr] = string.Copy(source[ctr]);
}
}
// </Snippet1>
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ private static void CopyStrings(string[] source, string[] target, int startPos)
throw new IndexOutOfRangeException("The source and target arrays must have the same number of elements.");

for (int ctr = startPos; ctr <= source.Length - 1; ctr++)
target[ctr] = String.Copy(source[ctr]);
target[ctr] = string.Copy(source[ctr]);
}
}
// </Snippet4>
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public static void Main()
Action<string[], string[], int, int> copyOperation = CopyStrings;
copyOperation(ordinals, copiedOrdinals, 3, 5);
foreach (string ordinal in copiedOrdinals)
Console.WriteLine(String.IsNullOrEmpty(ordinal) ? "<None>" : ordinal);
Console.WriteLine(string.IsNullOrEmpty(ordinal) ? "<None>" : ordinal);
}

private static void CopyStrings(string[] source, string[] target,
Expand All @@ -21,7 +21,7 @@ private static void CopyStrings(string[] source, string[] target,
throw new IndexOutOfRangeException("The source and target arrays must have the same number of elements.");

for (int ctr = startPos; ctr <= startPos + number - 1; ctr++)
target[ctr] = String.Copy(source[ctr]);
target[ctr] = string.Copy(source[ctr]);
}
}
// </Snippet2>
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public static void Main()
{ CopyStrings(s1, s2, pos, num); };
copyOperation(ordinals, copiedOrdinals, 3, 5);
foreach (string ordinal in copiedOrdinals)
Console.WriteLine(String.IsNullOrEmpty(ordinal) ? "<None>" : ordinal);
Console.WriteLine(string.IsNullOrEmpty(ordinal) ? "<None>" : ordinal);
}

private static void CopyStrings(string[] source, string[] target,
Expand All @@ -24,7 +24,7 @@ private static void CopyStrings(string[] source, string[] target,
throw new IndexOutOfRangeException("The source and target arrays must have the same number of elements.");

for (int ctr = startPos; ctr <= startPos + number - 1; ctr++)
target[ctr] = String.Copy(source[ctr]);
target[ctr] = string.Copy(source[ctr]);
}
}
// </Snippet3>
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public static void Main()
StringCopy copyOperation = CopyStrings;
copyOperation(ordinals, copiedOrdinals, 3, 5);
foreach (string ordinal in copiedOrdinals)
Console.WriteLine(String.IsNullOrEmpty(ordinal) ? "<None>" : ordinal);
Console.WriteLine(string.IsNullOrEmpty(ordinal) ? "<None>" : ordinal);
}

private static void CopyStrings(string[] source, string[] target,
Expand All @@ -26,7 +26,7 @@ private static void CopyStrings(string[] source, string[] target,
throw new IndexOutOfRangeException("The source and target arrays must have the same number of elements.");

for (int ctr = startPos; ctr <= startPos + number - 1; ctr++)
target[ctr] = String.Copy(source[ctr]);
target[ctr] = string.Copy(source[ctr]);
}
}
// </Snippet1>
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public static void Main()
=> CopyStrings(s1, s2, pos, num);
copyOperation(ordinals, copiedOrdinals, 3, 5);
foreach (string ordinal in copiedOrdinals)
Console.WriteLine(String.IsNullOrEmpty(ordinal) ? "<None>" : ordinal);
Console.WriteLine(string.IsNullOrEmpty(ordinal) ? "<None>" : ordinal);
}

private static void CopyStrings(string[] source, string[] target,
Expand All @@ -22,7 +22,7 @@ private static void CopyStrings(string[] source, string[] target,
throw new IndexOutOfRangeException("The source and target arrays must have the same number of elements.");

for (int ctr = startPos; ctr <= startPos + number - 1; ctr++)
target[ctr] = String.Copy(source[ctr]);
target[ctr] = string.Copy(source[ctr]);
}
}
// </Snippet4>
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ public class Example
public static void Main()
{
// Initialize array of characters from a to z.
Char[] chars = new Char[26];
char[] chars = new char[26];
for (int ctr = 0; ctr < 26; ctr++)
chars[ctr] = (char) (ctr + 0x0061);

Object obj = Activator.CreateInstance(typeof(String),
new Object[] { chars, 13, 10 } );
object obj = Activator.CreateInstance(typeof(string),
new object[] { chars, 13, 10 } );
Console.WriteLine(obj);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public static void Main()

for (int ctr = 0; ctr <= arguments.GetUpperBound(0); ctr++) {
object[] args = arguments[ctr];
object result = Activator.CreateInstance(typeof(String), args);
object result = Activator.CreateInstance(typeof(string), args);
Console.WriteLine("{0}: {1}", result.GetType().Name, result);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ public class Example
public static void Main()
{
ObjectHandle handle = Activator.CreateInstance("PersonInfo", "Person");
Object p = handle.Unwrap();
object p = handle.Unwrap();
Type t = p.GetType();
PropertyInfo prop = t.GetProperty("Name");
if (prop != null)
prop.SetValue(p, "Samuel");

MethodInfo method = t.GetMethod("ToString");
Object retVal = method.Invoke(p, null);
object retVal = method.Invoke(p, null);
if (retVal != null)
Console.WriteLine(retVal);
}
Expand Down