C#では、呼び出し元のプログラムに配列を返すことは可能ですか?それが不可能な場合は、すべて可能ではないと言ってください。もう1つの方法は、長い文字列を作成し、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;
}
}
_return yearsfiled_をwhileループの外側に移動すると、おそらくこのコードから何かを得る可能性が高くなります。 – Steve
リターンは外側に移動する必要があります。それは私の間違いでした。完了しました。ありがとう – Unnikrishnan
もちろん、配列を返すことは可能です。しかし、そのロジックのためにコードを完全に修正する必要があります。たとえば、空白行の役割や、空白以外の行のチェックは何ですか。 –