using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication3
{
class Program
{
private static int _counter;
private static String _name;
static void Main(string[] args)
{
Console.Write(messages(1));
_name = Convert.ToString(Console.ReadLine());
run();
Console.ReadKey();
}أن يكون الـmain فارغ من المعادلات دائماً
public static String messages(int messagenumber)
{
switch (messagenumber)
{
case 1 : return "Please write your name :";
case 2 : return "The lenght of of the name = :";
default: return "Program error, this program doesn't contine this further information";
}
}أنا أحب أن أعمل method خاص بطباعة الرسائل
public static void run()
{
char[] nameonchararray = convertor(_name);
findingthelenght(nameonchararray);
changinglatter(nameonchararray);
}مشان main ما يكون زحمة نعمل run method وتكون فية أوامر التشغيل للبرنامج
public static char[] convertor(String name) {
return name.ToCharArray();
} public static void changinglatter( char[] nameonchararray) { for (int i = 0; i < _counter; i++) { if (i == 0 || i % 2 == 0) { Console.Write(char.ToUpper(nameonchararray)); } else { Console.Write(char.ToLower(nameonchararray)); } } } public static void findingthelenght(char[] nameonchararray)
{
int counter = 0;
char temp;
try {
while (true)
{
temp = nameonchararray[counter];
counter++;
}
}catch (Exception ex){
Console.WriteLine( messages(2) + counter);
}
_counter = counter;
}
}
}طبعاً لو تلاحظون أن البرنامج مقسم كل فنكشن له و ظيفة واحدة فقط إشاء الله أكتب برنامج ثاني أوضح فية كيف تكتب method متعدد الاستخدام