String Type Variable in C#.Net

We already learn about variable and integer type variable in our previous tutorial. Now in this post we will learn about string type variable, how to declare, initialize and how to use string variable in with an example.

String Variable in C#.Net

The variable is a storage area for holding values that we will use later in our program.

String variable always stores text value in c#. In we use small string syntax for declare string variable. The string data types store the text value, a number of character. String variable store value always with in double quote.

Let’s understand String type of variable

In textbox control values are always string value, we use string variable for hold textbox value. If we want to get value from textbox control then we must use string type variable for store textbox value.

C# string variable declaration

<data_type> <Variable_name>


string strval;
here string = datatype and strval = variable name

here we assign value 10 to strval string variable.

Let’s an example in c# .net to understand string type variable in visual studio .Net.

Open Visual Studio –> New Website –> Add New Web form in Solution Explorer.

go to .cs page declare variable with string data types show like below screen.

String type variable in
String type variable in

Here, first we declare strval variable with string data types and after in second line we assign ‘Meera Academy’ value to variable strval. Above variable declaration first line shows green underling warring message, because we declare and initialize variable but we not use it in our program.


Let’s take second example to understand string variable in Design web page as like below screen along with one textbox, a button and a label control. here we store textbox value in string variable and then assign string variable value to label control for display output on web form.

String type variable example in
String type variable example in

below screen is a c# code for above example. At first line we assign textbox value to string variable strval and then assign strval variable value to label control.

String type variable example in
String type variable example in

Related ASP.Net Topics :

Learn about Datatypes in C#
Learn about Variable in C#

Subscribe us

If you liked this post, then please subscribe to our YouTube Channel for more video tutorials.

We hope that this tutorial helped you to understand about string type variable in C#.

Next, tutorial we will understand about float and double type variable in C#.

Leave a Reply

Your email address will not be published. Required fields are marked *