【问题标题】:Passing a parameter from class A method to class B将参数从 A 类方法传递给 B 类
【发布时间】:2012-12-03 06:30:17
【问题描述】:
//Class A
void OnChanged(object source, FileSystemEventArgs e)
{
XmlTextReader reader = new XmlTextReader("?"); <- How will I pass the "file" variable from Class B?
}

//Class B
public static bool myMethod(FileInfo file)
{
//some codes here
return false;
}

我知道您必须为此设置一些属性才能传递变量,但我还不确定从哪里开始。添加一些代码可以帮助我更好地理解属性。

【问题讨论】:

    标签: c# parameters parameter-passing


    【解决方案1】:
    //Class B
    public static FileInfo myFileProperty
    {
       get;
       set;
    }
    
    public static bool myMethod(FileInfo file)
    {
    //some codes here
    myFileProperty = file;
    return false;
    }
    
    
    //Class A
    void OnChanged(object source, FileSystemEventArgs e)
    {
    
    XmlTextReader reader = new XmlTextReader(ClassB.myFileProperty);
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-06-07
      • 2021-11-10
      • 2013-06-12
      • 1970-01-01
      • 1970-01-01
      • 2021-12-01
      • 2015-12-26
      相关资源
      最近更新 更多