Drop Down MenusCSS Drop Down MenuPure CSS Dropdown Menu

Wednesday 17 June 2015

STRINGS (CONCATENATION) IN C#


Today in Engineer's World, we are discussing a very important topic of C# -String in very easy way. Posted by +Manish Kumar Gautam +LIV WIRE +Asp.net Solutions


Click imaginationhunt.blogspot to see latest Blogs  

CONCATENATE STRINGS

Strings concatenation means joining and adding two different strings to make a single string.



Practical Implementation:

using System;

namespace AspnetSolutions
{
    class ConcatenateString
    {
        public static void Main()
        {
            string str1 = "imaginationhunt.";
            string str2 = "blogspot.in";

            Console.WriteLine(str1+str2);

        }
    }
}


Output

Use Concat() Method:
This method is used to concatenate string. Concat() method reside in String class. It has various overloaded constructor. It accepts object parameter and returns a single string

Click imaginationhunt.blogspot to see latest Blogs  

Practical Implementation: 

using System;

namespace AspnetSolutions
{
    class ConcatenateString
    {
        public static void Main()
        {
            string str1 = "imaginationhunt.";
            string str2 = "blogspot.in";

            int length = 25521;
 
            Console.WriteLine(str1+str2);

            Console.WriteLine(String.Concat(str1,str2));
            Console.WriteLine(String.Concat(str1,str2,length));


        }
    }
}


Output



To read STRINGS (CONCATENATION) IN C# Part 2 - Click here.

Related Questions:


 

Q-1 Select the output for the given set of code:

static void Main()
{
string s1 = "Hello"+"Asp.net"+"Solutions";
System.Console.WriteLine(s1);
System.Console.ReadLine();

}

A) HelloAsp.netSolutions
B) Hello Asp.net Solutions
C) Compile time error
D) Hello
Ans- Option(A).


Q-2 Which string operation does the below mentioned method defines? More than one option

public static string Concat(string str0, string str1)
 
a) method returns a string
b) string str1 is concatenated to the end of str0
c) can be used to concatenate any number of strings
d) None of the mentioned


Click imaginationhunt.blogspot to see latest Blogs

Ans- Option (A), (B), (C).
Explanation: (A) and (B) are correct because this method returns a string that contains str1 concatenated to the end of str0. 
Now, look at another form of Concat(), which concatenates three strings:
public static string Concat(string str0, string str1, string str2). 
Hence, any number of strings can be concatenated using this method. So option(C) is also correct.

 Keep learning and sharing...

No comments:

Post a Comment

Featured post

Think that makes you rich and richer

 Napolean said: “You can think and grow rich, but if you can be brought up like most people with work and you won't starve, this wil...