C# Programming - Strings - Discussion
Discussion Forum : Strings - General Questions (Q.No. 9)
9.
Which of the following will be the correct output for the C#.NET code snippet given below?
String s1="Kicit";
Console.Write(s1.IndexOf('c') + " ");
Console.Write(s1.Length);
Discussion:
12 comments Page 2 of 2.
Mohd Asif said:
1 decade ago
Hey guys I agree that index will be start from 0 then c is 2 but length should be 4 such as s1 (0) = k, s1 (1) = i, s1 (2) = c, s1 (3) = i, s1 (4) = t.
So length should be 4.
So length should be 4.
Stephanie said:
8 years ago
Why? Strings are like Arrays and have a zero-based index.
If we replace s1.IndexOf('c') with s1.IndexOf('K') we get the result : 0 5.
If we replace s1.IndexOf('c') with s1.IndexOf('K') we get the result : 0 5.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers