Write a C# program to find the length of a string without using library function


Introduction

I have used Visual Studio 2012 for debugging purpose. But you can use any version of visul studio as per your availability..


techstudy.org

HP 15 Core i3 7th gen Laptop(4GB, 1TB HDD, Windows 10) | Rs. 31,490

  1. using System;
  2. public class StringExercise
  3. {
  4. public static void Main()
  5. {
  6. string str;
  7. int length = 0;
  8.  
  9. Console.Write("Input the string : ");
  10. str = Console.ReadLine();
  11.  
  12. foreach (char chr in str)
  13. {
  14. length += 1;
  15.  
  16. }
  17. Console.Write("Length of the string is : {0}\n\n",length);
  18.  
  19. Console.ReadLine();
  20. }
  21. }

Result

C# language techstudy

     





Related Topics




Popular Posts