Quantcast
Channel: CodeFari
Viewing all articles
Browse latest Browse all 265

How does the data type String differ from string in C#?

$
0
0

What distinguishes these two and which one is more appropriate for use in C#?

string s = "Codefari";

String s = "Codefari";

Solution:

The distinction between these two statements is the case of the data type used to declare the variable. In C#, "string" with a lowercase "s" is a keyword that represents the built-in string data type. On the other hand, "String" with an uppercase "S" is a class from the .NET Framework that is used to create string objects.

In practice, both "string" and "String" can be used interchangeably in C#, as they are aliases of each other. However, it is a convention in C# to use "string" rather than "String" when declaring variables of string type.

Therefore, it is more appropriate to use "string s = "Codefari";" when declaring a variable of string type in C#.


Viewing all articles
Browse latest Browse all 265

Trending Articles