What will be the output of the following C# code snippet? [code] class Program { static void Main(string[] args) {

What will be the output of the following C# code snippet?
Code:
 class Program
 {
     static void Main(string[] args)
     {
         String s1 = "CSHARP";
         String s2 = s1.Replace('H','L');
         Console.WriteLine(s2);
         Console.ReadLine();
     }
 }
A. CSHAP
B. CSHP
C. CSHALP
D. CSHP
 
Answer: c
Explanation: Replace() method replaces all occurrences of a single character in invoking strings with another character. s1.Replace(‘H’,’L’) replaces every occurrence of ‘H’ in CSHARP by ‘L’, giving CSHALP.
Output:
Code:
CSHALP
 

Tìm kiếm

Back
Top