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;
}
}
答案 0 :(得分:1)
public string[] ExamnationOfReturnsFiled(string panreceived)
//功能
您正在返回类型而不是变量名称更改上面的方法签名
答案 1 :(得分:0)
您应该返回yearsfiled[]
。您的返回类型> python
Python 2.7.10 (default, Oct 23 2015, 19:19:21)
[GCC 4.2.1 Compatible Apple LLVM 7.0.0 (clang-700.0.59.5)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import six
>>> import xhtml2pdf.pisa
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Library/Python/2.7/site-packages/xhtml2pdf/pisa.py", line 3, in <module>
from xhtml2pdf.document import pisaDocument
File "/Library/Python/2.7/site-packages/xhtml2pdf/document.py", line 2, in <module>
from xhtml2pdf.context import pisaContext
File "/Library/Python/2.7/site-packages/xhtml2pdf/context.py", line 23, in <module>
import xhtml2pdf.parser
File "/Library/Python/2.7/site-packages/xhtml2pdf/parser.py", line 17, in <module>
from html5lib import treebuilders, inputstream
File "/Library/Python/2.7/site-packages/html5lib/__init__.py", line 16, in <module>
from .html5parser import HTMLParser, parse, parseFragment
File "/Library/Python/2.7/site-packages/html5lib/html5parser.py", line 2, in <module>
from six import with_metaclass, viewkeys, PY3
ImportError: cannot import name viewkeys
>>> exit()
是变量名称,而不是类型名称
答案 2 :(得分:0)
//来自调用程序。经过测试并成功。
string[] yearsfiled = new string[20];
yearsfiled = ExamnationOfReturnsFiled(item1);
//函数名称修改如下。
public static string[] ExamnationOfReturnsFiled(string panreceived)
{
Everything else as in the original post.
}
//经过测试。并发现成功。非常感谢@Midhun Mundayadan和@Eavidan。