سلام میخواستم بدونم اگه من یک کدی داشته باشم که نخوام توی فرم یک باشه ، یعنی یک کلاس جدا براش بسازم چیکار باید انجام بدم ؟
کد :
[CSHARP]
private string gt;
private string j;
[/CSHARP]
[CSHARP]
gt = textBox1.Text.ToLower().Substring(textBox1.Text.ToLower().IndexOf("enter the right answer to start chatting.") + 42);
gt = gt.Replace(" ", "");
gt = gt.Replace("=...", "");
gt = gt.Replace("thousand", "");
gt = gt.Replace("hundred", "");
gt = gt.Replace("and", ",");
gt = gt.Replace("ten", "10");
gt = gt.Replace("eleven", "11");
gt = gt.Replace("twelve", "12");
gt = gt.Replace("thirteen", "13");
gt = gt.Replace("fourteen", "14");
gt = gt.Replace("fifteen", "15");
gt = gt.Replace("sixteen", "16");
gt = gt.Replace("seventeen", "17");
gt = gt.Replace("eighteen", "18");
gt = gt.Replace("nineteen", "19");
gt = gt.Replace("twenty-", "2");
gt = gt.Replace("thirty-", "3");
gt = gt.Replace("forty-", "4");
gt = gt.Replace("fifty-", "5");
gt = gt.Replace("sixty-", "6");
gt = gt.Replace("seventy-", "7");
gt = gt.Replace("eighty-", "8");
gt = gt.Replace("ninety-", "9");
gt = gt.Replace("twenty", "20");
gt = gt.Replace("thirty", "30");
gt = gt.Replace("forty", "40");
gt = gt.Replace("fifty", "50");
gt = gt.Replace("sixty", "60");
gt = gt.Replace("seventy", "70");
gt = gt.Replace("eighty", "80");
gt = gt.Replace("ninety", "90");
gt = gt.Replace("one", "1");
gt = gt.Replace("two", "2");
gt = gt.Replace("three", "3");
gt = gt.Replace("four", "4");
gt = gt.Replace("five", "5");
gt = gt.Replace("six", "6");
gt = gt.Replace("seven", "7");
gt = gt.Replace("eight", "8");
gt = gt.Replace("nine", "9");
if (gt.ToLower().Contains("-"))
{
int y = Convert.ToInt32(gt.Substring(0, +1));
int x = Convert.ToInt32(gt.Substring(2, +1));
j = (y - x).ToString();
}
else if (gt.ToLower().Contains("+"))
{
int y = Convert.ToInt32(gt.Substring(0, +1));
int x = Convert.ToInt32(gt.Substring(2, +1));
j = (y + x).ToString();
}
else if (gt.ToLower().Contains("*"))
{
int y = Convert.ToInt32(gt.Substring(0, +1));
int x = Convert.ToInt32(gt.Substring(2, +1));
j = (y * x).ToString();
}
else if (gt.ToLower().Contains("whatisthe1stdigitof"))
{
j = gt.Substring(gt.IndexOf("of") + 2);
j = j.Substring(0, j.IndexOf("?") - 4);
}
else if (gt.ToLower().Contains("whatisthe2nddigitof"))
{
j = gt.Substring(gt.IndexOf("of") + 3);
j = j.Substring(0, j.IndexOf("?") - 3);
}
else if (gt.ToLower().Contains("whatisthe3rddigitof"))
{
j = gt.Substring(gt.IndexOf("of") + 4);
j = j.Substring(0, j.IndexOf("?") - 2);
}
else if (gt.ToLower().Contains("whatisthe4thdigitof"))
{
j = gt.Substring(gt.IndexOf("of") + 5);
j = j.Substring(0, j.IndexOf("?") - 1);
}
else if (gt.ToLower().Contains("whatisthe5thdigitof"))
{
j = gt.Substring(gt.IndexOf("of") + 6);
j = j.Substring(0, j.IndexOf("?") - 0);
}
else if (gt.ToLower().Contains("asdigits?"))
{
j = gt.Substring(gt.IndexOf("Whatis") + 6);
j = j.Substring(0, j.IndexOf("as") - 0);
}
else if (gt.ToLower().Contains("whichisthesmallest?"))
{
j = gt.Substring(gt.IndexOf("bers") + 4);
j = j.Substring(0, j.IndexOf(",w") - 0);
string[] s = null;
s = j.Split(',');
long lng = 0;
lng = Convert.ToInt64(s[s.GetLowerBound(0)]);
for (var i = s.GetLowerBound(0); i <= s.GetUpperBound(0); i++)
{
if (lng > Convert.ToInt64(s[i]))
{
lng = Convert.ToInt64(s[i]);
}
}
j = lng.ToString();
}
else if (gt.ToLower().Contains("whichisthebiggest?"))
{
j = gt.Substring(gt.IndexOf("bers") + 4);
j = j.Substring(0, j.IndexOf(",w") - 0);
string[] s = null;
s = j.Split(',');
long lng = 0;
lng = Convert.ToInt64(s[s.GetUpperBound(0)]);
for (var i = s.GetLowerBound(0); i <= s.GetUpperBound(0); i++)
{
if (lng < Convert.ToInt64(s[i]))
{
lng = Convert.ToInt64(s[i]);
}
}
j = lng.ToString();
}
else if (gt.ToLower().Contains("the1stnumberof"))
{
j = gt.Substring(gt.IndexOf("of") + 2);
j = j.Substring(0, j.IndexOf("is?") - 0);
string[] s = null;
s = j.Split(',');
j = s[0].ToString();
}
else if (gt.ToLower().Contains("the2ndnumberof"))
{
j = gt.Substring(gt.IndexOf("of") + 2);
j = j.Substring(0, j.IndexOf("is?") - 0);
string[] s = null;
s = j.Split(',');
j = s[1].ToString();
}
else if (gt.ToLower().Contains("the3rdnumberof"))
{
j = gt.Substring(gt.IndexOf("of") + 2);
j = j.Substring(0, j.IndexOf("is?") - 0);
string[] s = null;
s = j.Split(',');
j = s[2].ToString();
}
else if (gt.ToLower().Contains("the4thnumberof"))
{
j = gt.Substring(gt.IndexOf("of") + 2);
j = j.Substring(0, j.IndexOf("is?") - 0);
string[] s = null;
s = j.Split(',');
j = s[3].ToString();
}
else if (gt.ToLower().Contains("the5thnumberof"))
{
j = gt.Substring(gt.IndexOf("of") + 2);
j = j.Substring(0, j.IndexOf("is?") - 0);
string[] s = null;
s = j.Split(',');
j = s[4].ToString();
}
MessageBox.Show("Javabe sahih " + j + " Mibashad");
[/CSHARP]
خب اگه من بخوام اینو توی کلاس تعریف کنم ، کدش چطوری میشه ؟
و اگه بخوام وقتی مثلا سوال پرسیده شد ، برنامه به این کلاس رجوع کنه و جواب رو بدست بیاره و جواب رو به کاربر نشون بده ، چیکار باید انجام بدم ؟
یک سوال دیگه ، آیا این کدها به نظر شما که کدنویسیتون قوی تره درست هستند؟ اگه نه ، پس کد رو به چه شکلی تغییر میدید ؟
ممنون