是否有可能在C#中將數組返回給調用程序?如果不可能,請說這不是全部可能。另一種方法是創建一個長字符串並使用string.split()。但那看起來不太好。 ExamnationOfReturnsFiled(「ABCDE1234E」)//調用程序。是否有可能在C#中將數組返回給調用程序?
public yearsfiled[] ExamnationOfReturnsFiled(string panreceived) //function.
{
int k = 0; //to increment the array element.
string item = panreceived; //string value received call program.
string[] yearsfiled = new string[20];//Declaring a string array.
Regex year = new Regex(@"[0-9]{4}-[0-9]{2}");//to capture 2012-13 like entries.
using (StreamReader Reader1 = new StreamReader(@"C: \Users\Unnikrishnan C\Documents\Combined_Blue_Book.txt"))
{
Regex tofindpan = new Regex(item);//Regular Expression to catch the string from the text file being read.
bool tosearch = false;
Regex blank = new Regex(@"^\s*$"); //to detect a blank line.
while ((str.line1 = Reader1.ReadLine()) != null)
{
Match Tofindpan = tofindpan.Match(@"[A-Z]{5}[0-9]{4}[A-Z]{1}");
Match Blank = blank.Match(line1);
if (Blank.Success)
{
tosearch = false;
}
if (Tofindpan.Success)
{
tosearch = true; //when true the
}
if (tosearch == true)
{
Match Year = year.Match(str.line1);
if (Year.Success)
{
yearsfiled[k] = Year.Value;
k++;
}
}
}
return yearsfiled;
}
}
如果您在while循環之外移動您的_return年份_filed_,您可能有更好的機會從此代碼中獲取某些內容。 – Steve
返回應該移到外面。這是我的錯誤。完成。謝謝 – Unnikrishnan
當然可以返回一個數組。但是,您應該徹底修改您的代碼以獲取其邏輯。例如,panreceived的作用是什麼,或者檢查非空行。 –