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);
3 6
2 5
3 5
2 6
3 7
Answer: Option
Explanation:
No answer description is available. Let's discuss.
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.

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.


Post your comments here:

Your comments will be displayed after verification.