In C#, ToUpperInvariant() returns an uppercase copy of a string using the invariant culture: fixed casing rules that are identical on every computer. It is the same as ToUpper(CultureInfo.InvariantCulture), just shorter.
It is the right tool for values that programs exchange: currency codes like USD, country codes, product SKUs, and identifiers. The original string stays unchanged, as always.
This is an instance member of System.String. Call it on a string variable, such as text.ToUpperInvariant(...). Calling it on a null variable throws NullReferenceException. C# strings are immutable: ToUpperInvariant() never changes the original text. It gives back a new string (or the same one when there is nothing to change), so keep the result in a variable.
Syntax
No arguments. Call it on the string you want in capitals.
Works, but OrdinalIgnoreCase is the faster way to compare.
It handles all Unicode letters, not only A to Z: é becomes É. It does not use the current culture, so lowercase i always becomes plain I, even on a Turkish system.
Library declarations
C#
public string ToUpperInvariant();
Parameters
Parameter
Description
None
ToUpperInvariant() takes no parameters.
Return Value
Return Value
Description
string
A new uppercase copy using invariant casing rules.
C# Examples
Example 1 — Uppercase an Order Reference
Turn a mixed order reference into capitals without touching the symbols.
C#
using System;
class Program {
static void Main() {
string order = "order #a12b";
Console.WriteLine(order.ToUpperInvariant());
Console.WriteLine(order);
}
}
Output
ORDER #A12B
order #a12b
How It Works
Letters inside codes. The a and b mixed with digits become A and B.
Digits and symbols.#, 1, and 2 are copied as they are.
The same output everywhere. No culture setting can change this result.
Source unchanged. The second line shows the original lowercase reference.
Example 2 — Normalize Currency Codes
Users type currency codes in different ways. Uppercase each one and check one of them.
C#
using System;
class Program {
static void Main() {
string[] codes = { "usd", "Eur", "GBP" };
foreach (string c in codes) {
Console.WriteLine(c.ToUpperInvariant());
}
Console.WriteLine(codes[1].ToUpperInvariant() == "EUR");
}
}
Output
USD
EUR
GBP
True
How It Works
Three spellings. All lowercase, mixed, and already uppercase.
One shape out. After the call, every code is in capitals, so they can be stored and compared the same way.
Already uppercase is fine.GBP comes back with the same text.
Exact check afterwards. Once both sides are normalized, a plain == is enough: Eur matches EUR.
Example 3 — Keep Identifiers Stable on Any Machine
An identifier with lowercase i letters shows why invariant rules matter.
C#
using System;
class Program {
static void Main() {
string key = "item-id";
string upper = key.ToUpperInvariant();
Console.WriteLine(upper);
Console.WriteLine(upper.Length);
Console.WriteLine(key);
}
}
Output
ITEM-ID
7
item-id
How It Works
Two risky letters.item-id contains two lowercase is.
Plain I every time. Invariant rules turn each into I, giving ITEM-ID. A plain ToUpper() on a Turkish system would give İTEM-İD instead.
Length unchanged. 7 characters go in and 7 come out.
Original still lowercase.key was not modified.
Frequently Asked Questions
It returns an uppercase copy of the string using the invariant culture, so the result is the same on every machine.
Use it for identifiers, codes, keys, and any text that code stores or compares. Use ToUpper with a culture for text that is shown to people.
Yes. Both use the invariant culture and give the same result.
No. Use ToUpperInvariant for an uppercase copy, or StringComparison.OrdinalIgnoreCase to compare without case.
No. It returns a new string. Strings in C# are immutable.