C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Communities   Interview   Jobs   Projects   Offshore Development    
Silverlight Tutorials | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Revenue Sharing |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...

New Feature: Community Sites: Create your own .NET community website and start earning from Google AdSense ! It's Free !






string type in C#.NET


Posted Date: 15 Aug 2008    Resource Type: Code Snippets    Category: String Manipulations
Author: Gaurav AroraMember Level: Gold    
Rating: Points: 10



First of all String is of reference type so, it is stored on the heap rather than on a stack. So whenever you assign a string variable to another string variable then it means you are creating two references of same string.

Lets take a look on following example:


/* This Example is a part of different
* examples shown in Book:
* C#2005 Beginners: A Step Ahead
* Written by: Gaurav Arora
* Reach at : gaurav.aroraose@yahoo.co.in*/


// File name : stringCS.cs

using System;

namespace CSharp.AStepAhead.stringCS
{

class stringCS
{
static void Main()
{
string str = "This is example shows the various string features ";
string str1 = "This is first String";
string str2 = "This is second String";
string str3;
Console.WriteLine("{0}\n", str);
Console.WriteLine("This is string str1 :{0}\n", str1);
Console.WriteLine("This is string str2 :{0}\n", str2);
str3 = str1 + str2;
Console.WriteLine("String Concatenation : {0}", str3);
Console.WriteLine("str1 has {0}characters", str1.Length);
str="s";
str3 = "ESS";
string res;

if (str1.Contains(str) == true)
res = "Yes";
else
res = "No";
Console.WriteLine("Does str1 contains \'{0}\':{1}", str,res);
Console.WriteLine("Str2 in upper case {0}", str2.ToUpper());
Console.WriteLine("Str1 in lower case {0}", str1.ToLower());
Console.WriteLine("In Str1 character \'{0}\' is replaced by character \'{1}\' : \nnow str1 = {2}", str,str3, str1.Replace(str, str3));

}
}
}


Hope the above tiny article elaborate the Title.

For more details, visit http://www.msdotnetheaven.com/ChaptersCsharp/csharplanguagei.htm




Responses


No responses found. Be the first to respond and make money from revenue sharing program.

Feedbacks      
Popular Tags   What are tags ?   Search Tags  
String primitive data type  .  String in c#.net  .  String in C#  .  String data type in .net  .  Inteview  .  Handling strings in C#  .  C# Syntax  .  Article  .  .net  .  

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: Substring Function in Sql Server
Previous Resource: Merging Two String Array
Return to Discussion Resource Index
Post New Resource
Category: String Manipulations


Post resources and earn money!
 
Related Resources



dotNet Slackers   BizTalk Adaptors    Web Design


Contact Us    Privacy Policy    Terms Of Use