C# String ToUpperOrdinal() Method

Beginner
5 min read
Updated: Nov 2026
3 examples
Not a built-in method

Definition

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 no ToUpperOrdinal() 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 insteadWhen to use it
text.ToUpperInvariant()You need an uppercase copy that is the same on every computer.
string.Equals(a, b, StringComparison.OrdinalIgnoreCase)You need to compare without case.
text.StartsWith("GET", StringComparison.OrdinalIgnoreCase)You need a case-insensitive prefix check.
char.ToUpperInvariant(c)You uppercase a single character.

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

ParameterDescription
NoneToUpperOrdinal() does not exist, so it has no parameters. ToUpperInvariant() takes none either.
comparisonTypeFor comparison methods: pass StringComparison.OrdinalIgnoreCase.

Return Value

Return ValueDescription
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);
    }
}

How It Works

  1. No ToUpperOrdinal. The compiler would reject text.ToUpperOrdinal(), so the real method is used.
  2. Capitals with fixed rules. Every letter becomes uppercase; the colon and the space stay.
  3. Never machine-dependent. The invariant culture guarantees this output on any system.
  4. 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");
    }
}

How It Works

  1. Rules say case does not matter. HTTP treats CONTENT-TYPE and Content-Type as the same header name.
  2. Direct ignore-case compare. string.Equals with OrdinalIgnoreCase returns True without making an uppercase copy of either side.
  3. Prefix check, same option. StartsWith accepts the same comparison and also returns True.
  4. == 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());
    }
}

How It Works

  1. Codes, not cultures. In ASCII, 'a' is 97 and 'A' is 65. Every lowercase letter is exactly 32 above its capital.
  2. Only a to z. The if leaves the dash and the digits alone, because they are outside that range.
  3. Cast back to char. c - 32 is an int, so (char) turns it into a character again.
  4. 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.

Next: Trim()

Remove spaces (or chosen characters) from both ends of a string.

Trim() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

7 people found this page helpful