String vs string in C
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.
Introduction
In C#, string and String are not two different data types. string is just the language keyword alias for System.String, so the difference is about syntax and style rather than behavior, performance, or memory layout.
They Compile To The Same Type
These declarations all describe the same .NET type:
At runtime there is no distinction between those three variables. They are all System.String instances.
That means there is no performance advantage to choosing one spelling over the other.
Why string Is Usually Preferred
C# provides keyword aliases for several common CLR types:
- '
stringforSystem.String' - '
intforSystem.Int32' - '
boolforSystem.Boolean'
Most C# code uses those aliases for ordinary declarations because they read like natural C# instead of framework-qualified type names.
That is why most style guides prefer string in method signatures, local variables, fields, and properties.
Where String Still Shows Up Naturally
You will still see String in some situations, especially when calling static members on the type:
Some teams also prefer framework type names in reflection-heavy or cross-language code because they want consistency with other System.* types. That is a convention choice, not a technical requirement.
Another practical difference is that string works without using System;, while String usually needs either that namespace import or the fully qualified name System.String.
Consistency Matters More Than The Spelling
Most teams pick one style for normal declarations and stick to it. In C# projects, that usually means keyword aliases such as string, int, and bool for variables, parameters, properties, and return types.
You might still see StringComparer, StringBuilder, or String.IsNullOrEmpty, because those are actual framework type names and static members. That does not conflict with using string for local declarations. The important part is internal consistency, since mixed style makes the code look accidental.
Nullability Does Not Change The Story
Nullable reference types do not create a new distinction here. These two mean the same thing:
Most developers still prefer string? because it reads more naturally in C# code.
What Actually Matters More Than The Alias
The real string decisions in C# are not about string versus String. They are about:
- whether a value can be null
- how you compare strings
- culture-aware versus ordinal operations
- allocation patterns and interpolation
- encoding when data crosses process or network boundaries
Those choices affect correctness and performance. The alias choice mostly affects consistency.
Common Pitfalls
- Thinking
stringis a primitive value type whileStringis a reference type. - Expecting a performance difference between the two spellings.
- Using
Stringin ordinary declarations without importingSystem. - Mixing both styles randomly in the same file and making the code feel inconsistent.
- Assuming framework names like
StringBuildermean you should also replace everystringkeyword in your declarations. - Spending too much energy on the alias question while ignoring actual string-handling concerns.
Summary
- '
stringis the C# alias forSystem.String.' - '
string,String, andSystem.Stringall represent the same runtime type.' - There is no behavior or performance difference between them.
- Use
stringfor normal C# declarations unless your codebase has a deliberate convention otherwise. - Keep the codebase consistent, and focus more on comparison rules and null handling than on the alias itself.
Related reading
- String was not recognized as a valid DateTime format dd/MM/yyyy
- String.Format - how it works and how to implement custom formatstrings
- string.IsNullOrEmptystring vs. string.IsNullOrWhiteSpacestring
- String.Join method that ignores empty strings?
- String.Join vs. StringBuilder which is faster?
- String.Replace vs. StringBuilder.Replace
- String.Split only on first separator in C?
- string.ToLower and string.ToLowerInvariant

OOD Fundamentals
Master object-oriented design from first principles, SOLID, design patterns, and classic interview problems with hands-on coding.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.