Short answer: there is no String.ToUpperOrdinal() in C#. .NET uses the word “ordinal” for comparisons (StringComparison.Ordinal and OrdinalIgnoreCase), not for case conversion.
If you want capital letters that never depend on the machine, call ToUpperInvariant(). If you only want to check two strings while ignoring case, pass StringComparison.OrdinalIgnoreCase to Equals, StartsWith, EndsWith, or IndexOf; no uppercase copy is needed.
Not a real member.System.String has noToUpperOrdinal() method in any .NET version. text.ToUpperOrdinal() fails to compile with error CS1061. This page shows the real alternatives instead. All of them leave the original string unchanged, because C# strings are immutable.
Syntax
No built-in method — use these instead. These calls are all part of .NET.
C#
string text = "status: ok";
// text.ToUpperOrdinal(); // error CS1061: no such method
string upper = text.ToUpperInvariant(); // "STATUS: OK"
bool match = text.StartsWith("STATUS", StringComparison.OrdinalIgnoreCase); // True
char c = char.ToUpperInvariant('q'); // 'Q'
Use this instead
When to use it
text.ToUpperInvariant()
You need an uppercase copy that is the same on every computer.
For text you know is plain English letters (ASCII), uppercasing is just “subtract 32 from the code of a to z”, which Example 3 shows. In .NET 8 and later, System.Text.Ascii has span-based helpers for that case. For general text, ToUpperInvariant() is correct and simpler.
Real declarations of the alternatives
C#
// System.String
public string ToUpperInvariant();
public string ToUpper(CultureInfo? culture);
public bool StartsWith(string value, StringComparison comparisonType);
// System.Char
public static char ToUpperInvariant(char c);
Parameters
Parameter
Description
None
ToUpperOrdinal() does not exist, so it has no parameters. ToUpperInvariant() takes none either.
comparisonType
For comparison methods: pass StringComparison.OrdinalIgnoreCase.
Return Value
Return Value
Description
string (ToUpperInvariant)
A new uppercase copy using invariant rules.
bool (comparisons)
true when the texts match with case ignored.
C# Examples
Example 1 — The Built-In Replacement: ToUpperInvariant
Get culture-safe capitals with the method that really exists.
C#
using System;
class Program {
static void Main() {
string text = "status: ok";
Console.WriteLine(text.ToUpperInvariant());
Console.WriteLine(text);
}
}
Output
STATUS: OK
status: ok
How It Works
No ToUpperOrdinal. The compiler would reject text.ToUpperOrdinal(), so the real method is used.
Capitals with fixed rules. Every letter becomes uppercase; the colon and the space stay.
Never machine-dependent. The invariant culture guarantees this output on any system.
Copy only. The second line shows the lowercase original.
Example 2 — Match HTTP Header Names Without Uppercasing
Header names are case-insensitive. Compare them directly with OrdinalIgnoreCase.
C#
using System;
class Program {
static void Main() {
string header = "CONTENT-TYPE";
Console.WriteLine(string.Equals(header, "Content-Type", StringComparison.OrdinalIgnoreCase));
Console.WriteLine(header.StartsWith("content", StringComparison.OrdinalIgnoreCase));
Console.WriteLine(header == "Content-Type");
}
}
Output
True
True
False
How It Works
Rules say case does not matter. HTTP treats CONTENT-TYPE and Content-Type as the same header name.
Direct ignore-case compare.string.Equals with OrdinalIgnoreCase returns True without making an uppercase copy of either side.
Prefix check, same option.StartsWith accepts the same comparison and also returns True.
== stays exact. The plain operator compares codes exactly, so it prints False.
Example 3 — What “Ordinal Uppercase” Means for ASCII
Build capitals by hand for plain a to z, using character codes only, and check the answer against ToUpperInvariant().
C#
using System;
class Program {
static void Main() {
string s = "abc-123";
char[] chars = s.ToCharArray();
for (int i = 0; i < chars.Length; i++) {
char c = chars[i];
if (c >= 'a' && c <= 'z') {
chars[i] = (char)(c - 32);
}
}
string upper = new string(chars);
Console.WriteLine(upper);
Console.WriteLine(upper == s.ToUpperInvariant());
}
}
Output
ABC-123
True
How It Works
Codes, not cultures. In ASCII, 'a' is 97 and 'A' is 65. Every lowercase letter is exactly 32 above its capital.
Only a to z. The if leaves the dash and the digits alone, because they are outside that range.
Cast back to char.c - 32 is an int, so (char) turns it into a character again.
Matches for ASCII only. The result equals ToUpperInvariant() here, but this loop would ignore letters like é. Use the built-in method for real text.
Frequently Asked Questions
No. System.String has no ToUpperOrdinal method, and calling it gives compiler error CS1061. Use ToUpperInvariant() for an uppercase copy or StringComparison.OrdinalIgnoreCase for comparisons.
ToUpperInvariant(). It uppercases with fixed invariant rules, so the result is the same on every computer.
Use string.Equals(a, b, StringComparison.OrdinalIgnoreCase). It is faster than uppercasing both strings and avoids culture problems.
It means comparing by the numeric UTF-16 code of each character, without language rules. OrdinalIgnoreCase does the same while ignoring letter case.
Only for the ASCII letters a to z. It does not handle accented or non-Latin letters. Use ToUpperInvariant() for general text.