如何从该函数返回另一个arraylist []时将数组列表传递给函数。 [英] How to pass array list to a function while returning another arraylist[] from that function.

查看:135
本文介绍了如何从该函数返回另一个arraylist []时将数组列表传递给函数。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用以下代码:



私人密封类BackgroundWorkState 
{
public ArrayList [] str {get;组; }
public ArrayList searchtext_pass {get;组; }
// public string SomethingElse {get;组; }
}

private void button1_Click(object sender,EventArgs e)
{
BackgroundWorkState workerState = new BackgroundWorkState
{
searchtext_pass = ReadMSXls (),
str = ReadMsWord(),
};

backgroundWorker.RunWorkerAsync(workerState);
}





我需要将searchtext_pass传递给函数ReadMsWord(),但是当我尝试
$时b $ b

 str = ReadMsWord(searchtext_pass)



它表示searchtext_pass在此上下文中不可用。请建议。

解决方案

searchtext_pass BackgroundWorkState class - 所以你需要一个类的实例来访问它 - 正如你需要一个汽车的实例才能看到手套箱!



所以你需要这样的东西:

 str = ReadMsWord(myInstanceOfABackgroundWorkState.searchtext_pass); 



但是你不能轻易访问它,因为它是你正在尝试构建的类实例的属性,所以它还不存在!

试试这个:

 BackgroundWorkState workerState =  new  BackgroundWorkState(); 
workerState.searchtext_pass = ReadMSXls();
workerState.str = ReadMsWord(workerState.searchtext_pass);


创建带有参数的BackgroundWorkState构造函数。然后在调用

BackgroundWorkState workerState = new BackgroundWorkState设置参数...



不清楚ReadMSXLs()和ReadMSWord是类方法还是外部来源...但无论如何你在后台工作状态的构造函数中设置搜索文本(也就是你在实例化BackgroundWorkState之前调用ReadMSXls。



我希望有帮助:)

I'm using the following code:

private sealed class BackgroundWorkState
        {
            public ArrayList[] str { get; set; }
            public ArrayList searchtext_pass { get; set; }
            //public string SomethingElse { get; set; }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            BackgroundWorkState workerState = new BackgroundWorkState
                 {
                     searchtext_pass = ReadMSXls(),
                     str = ReadMsWord(),
                 };
    
    backgroundWorker.RunWorkerAsync(workerState);
        }



I need to pass the searchtext_pass to the function ReadMsWord(), but when I try

str=ReadMsWord(searchtext_pass)


it says searchtext_pass is not available in this context. Please advice.

解决方案

searchtext_pass is a property of the BackgroundWorkState class - so you need an instance of the class in order to access it - just as you need an instance of a car in order to look in the glove box!

So you need something like:

str=ReadMsWord(myInstanceOfABackgroundWorkState.searchtext_pass);


But you can't easily access it because it's a property of the class instance you are trying to construct so it doesn't really exist yet!
Try this:

BackgroundWorkState workerState = new BackgroundWorkState();
workerState.searchtext_pass = ReadMSXls();
workerState.str = ReadMsWord(workerState.searchtext_pass);


Create BackgroundWorkState constructor which takes the parameter. Then in calling
BackgroundWorkState workerState = new BackgroundWorkState set the parameter...

Not clear if ReadMSXLs() and ReadMSWord are class methods or outside sources...but anyhow you set search text in constructor of the background work state (that is you call ReadMSXls before instantiating BackgroundWorkState.

I hope that helps :)


这篇关于如何从该函数返回另一个arraylist []时将数组列表传递给函数。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆