.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
	

Tags:

Asp.net Convert String To ImageC# DateTime ToString()C# foreach loopRemoving aspnet runtime from IISASP net Write Text On Image C#.net and Vb.net programHow to Pass To Query String In Asp.netASp.net 2.0 step by step Membership Provider Asp.net delete file file on Server C#.net and VB.net codeRemove internet explorer[C#] Remove Last Character From StringDateTime format Time String

Author

My name is Satalaj, but people call me Sat. Here is my homepage: . I live in Pune, PN and work as a Software Engineer. I'm former MVP in ASP.net year 2010.
Disclaimer: Views or opinion expressed here are my personal research and it has nothing to do with my employer. You are free to use the code, ideas/hints in your projects. However, you should not copy and paste my original content to other web sites. Feel free to copy or extend the code.
If you want to fight with me, this website is not for you.
 

I'm Satalaj.