Tutorialsteacher

Follow Us

Articles
  • C#
  • C# OOP
  • ASP.NET Core
  • ASP.NET MVC
  • LINQ
  • Inversion of Control (IoC)
  • Web API
  • JavaScript
  • TypeScript
  • jQuery
  • Angular 11
  • Node.js
  • D3.js
  • Sass
  • Python
  • Go lang
  • HTTPS (SSL)
  • Regex
  • SQL
  • SQL Server
  • PostgreSQL
  • MongoDB
Entity Framework Extensions - Boost EF Core 9
  Bulk Insert
  Bulk Delete
  Bulk Update
  Bulk Merge
  • All
  • C#
  • MVC
  • Web API
  • Azure
  • IIS
  • JavaScript
  • Angular
  • Node.js
  • Java
  • Python
  • SQL Server
  • SEO
  • Entrepreneur
  • Productivity

Difference between string and String in C#

Essentially, there is no difference between string and String (capital S) in C#.

String (capital S) is a class in the .NET framework in the System namespace. The fully qualified name is System.String. Whereas, the lower case string is an alias of System.String.

Consider the following example.

Example: Check string type
string str1= "Hello";
String str2 = "World!";
            
Console.WriteLine(str1.GetType().FullName); // System.String
Console.WriteLine(str2.GetType().FullName); // System.String
Try it

As you can see in the above example, the full name of both types are System.String. So, this proves that both are same.

Write string and String in .cs file in Visual Studio and put the cursor on it and press F12. Both will take you to the sealed class String.

It is recommended to use string (lower case) over String. However, it's a matter of choice. You can use any of them. Many developers use string to declare variables in C# and use System.String class to use any built-in string methods e.g., String.IsNullOrEmpty().

Please note that you must import System namespace at the top of your .cs file to use String class, whereas string keyword can be used directly without any namespace.

.NET includes different aliases for different types. The following table lists data type aliases.

Alias.NET TypeType
byteSystem.Bytestruct
sbyteSystem.SBytestruct
intSystem.Int32struct
uintSystem.UInt32struct
shortSystem.Int16struct
ushortSystem.UInt16struct
longSystem.Int64struct
ulongSystem.UInt64struct
floatSystem.Singlestruct
doubleSystem.Doublestruct
charSystem.Charstruct
boolSystem.Booleanstruct
objectSystem.ObjectClass
stringSystem.StringClass
decimalSystem.Decimalstruct
DateTimeSystem.DateTimestruct
TUTORIALSTEACHER.COM

TutorialsTeacher.com is your authoritative source for comprehensive technologies tutorials, tailored to guide you through mastering various web and other technologies through a step-by-step approach.

Our content helps you to learn technologies easily and quickly for learners of all levels. By accessing this platform, you acknowledge that you have reviewed and consented to abide by our Terms of Use and Privacy Policy, designed to safeguard your experience and privacy rights.

[email protected]

ABOUT USTERMS OF USEPRIVACY POLICY
copywrite-symbol

2024 TutorialsTeacher.com. (v 1.2) All Rights Reserved.