c#中是否有可能将一个数组返回给调用程序?
本文关键字:返回 数组 一个 调用 程序 是否 有可能 | 更新日期: 2023-09-27 18:08:40
在c#中是否可以将数组返回给调用程序?如果它是不可能的,请说它不是完全可能的。另一种替代方法是创建一个长字符串并使用string.split()。但这看起来不太好。ExamnationOfReturnsFiled("ABCDE1234E")//调用程序。
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;
}
}
public string[] ExamnationOfReturnsFiled(string panreceived)
//function
您返回的是类型而不是变量名,请像上面那样更改方法签名
您应该返回一个string[]
。返回类型yearsfiled[]
是变量名,而不是类型名
//从调用程序。测试成功。
string[] yearsfiled = new string[20];
yearsfiled = ExamnationOfReturnsFiled(item1);
//函数名修改如下
public static string[] ExamnationOfReturnsFiled(string panreceived)
{
Everything else as in the original post.
}
//已经测试过了。并且成功了。非常感谢@Midhun Mundayadan和@Eavidan。