在c#中调用一个函数的变量到另一个函数

时间:2016-04-04 21:11:02

标签: c#

我需要调用字符串" final"在函数emp2中。当我尝试它时说"最终不存在"。这两个函数都在不同的类文件中。

internal class emp
{
    internal void empl(int id, string name, string sal)
    {
        empdet test = new empdet(id, name, sal);
        string final = test.ToString();
    }
}

public class empdetls
{
    public static void emp2( XElement element)
    {
        XElement element = XElement.Parse(final);

        // ...
    }
}

任何帮助将不胜感激。

2 个答案:

答案 0 :(得分:0)

你应该使用私人领域。

public class emp
{
       private String final;
        internal void empl(int id, string name, string sal)
        {

           empdet test = new empdet(id, name, sal);
           final = test.ToString();
        }

        public static void emp2( XElement element)
        {

           XElement element = XElement.Parse(final);
           .....
           .....
        }  
}

答案 1 :(得分:0)

只需将参数传递给static方法即可。无论如何,static方法应该没有特定的实例。

public static void emp2(XElement element, string final)
{
    // ...
}