.net String vs string

.net String vs string .net-String vs. string

String vs string, in .net you might have seen both String and string classes and got confusion about which one to use. Well, there is no difference at all. string is Alias of System.String. Here we will see how to create alias and use it, in C#.net and VB.net languages.

C# string alias

Here I'm creating new alias for System.String as strings. This way we will create new string using strings. I have suffixed s to string keyword.

using System;
using strings = System.String;
namespace Csharp.stringVsString.Example
{
class Program
{
static void Main(string[] args)
{      
strings str = "This is my string referred by my alias";     
Console.WriteLine(str);    
}
}
}

Vb.net example of string vs. String alias. Here we are creating new alias as strings for System.String

Imports System
Imports strings = System.String
Namespace Csharp.stringVsString.Example
Class Program
Private Shared Sub Main(args As String())
Dim str As strings = "This is my string referred by my alias"
Console.WriteLine(str)
End Sub
End Class
End Namespace
Output
This is my string referred by my alias.

How to create alias in C#

Here are examples of alias used in .net

	Alias 	         CLR type
	using string =	System.String
	using sbyte =	System.SByte
	using byte =	System.Byte
	using short =	System.Int16
	using ushort =	System.UInt16
	using int =	System.Int32
	using uint =	System.UInt32
	using long =	System.Int64
	using ulong =	System.UInt64
	using char =	System.Char
	using float =	System.Single
	using double =	System.Double
	using bool =	System.Boolean
	using decimal =	System.Decimal
	

Currently rated 5.0 by 1 people

  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5