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

  • برمجة سي شارب
  • برمجة

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

Test Data :
Input the string : daafoor.com
Expected Output :

Length of the string is : 12 

الأجوبة

using System;  
public class Exercise2
{  
    public static void Main() 
{
    string str; /* Declares a string of size 100 */
    int l= 0;
      Console.Write("\n\nFind the length of a string :\n");
      Console.Write("---------------------------------\n"); 	
      Console.Write("Input the string : ");
      str = Console.ReadLine();
         foreach(char chr in str)
        {
            l += 1;
        }

   Console.Write("Length of the string is : {0}\n\n", l);
	}
}
هل كان المحتوى مفيد؟

تبحث عن مدرس اونلاين؟

محتاج مساعدة باختيار المدرس الافضل؟ تواصل مع فريقنا الان لمساعدتك بتأمين افضل مدرس
ماهو التخصص الذي تبحث عنه؟
اكتب هنا...