String Type Variable in C#.Net



We already learn about variable and integer type variable in our previous asp.net tutorial. Now in this c#.net post we will learn about string type variable, how to declare, initialize and how to use string variable in c#.net 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 c#.net 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 c#.net 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>

Example:

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

strval=10;
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 c#.net
String type variable in c#.net

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.


Example

Let’s take second example to understand string variable in c#.net. 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 c#.net
String type variable example in c#.net

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 c#.net
String type variable example in c#.net

Related ASP.Net Topics :

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


Subscribe us

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

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


Next, asp.net 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 *