试图在if语句中调用方法,但我收到错误CS7036

时间:2017-11-09 18:07:49

标签: c#

我试图在if语句中调用我的方法但是我收到错误CS7036没有给出的参数对应于'FixTheDomain.CreateTrust(string,string)'所需的形式参数'sourceForestName'

这是我调用的方法

public void CreateTrust(string sourceForestName, string targetForestName)
    {
        Forest sourceForest = Forest.GetForest(new DirectoryContext(
            DirectoryContextType.Forest, sourceForestName));

        Forest targetForest = Forest.GetForest(new DirectoryContext(
            DirectoryContextType.Forest, targetForestName));

        // create an inbound forest trust

        sourceForest.CreateTrustRelationship(targetForest,
            TrustDirection.Outbound);

这是我称之为

的地方
private void FixTrust_Click(object sender, EventArgs e)
    {
        Validate();
        if (Validate() == true)
        {
            CreateTrust();
        }  

    }

我真的没有抓住它希望我从if。

中获取这些参数的地方

2 个答案:

答案 0 :(得分:4)

编译器希望您使用它需要的两个参数调用该方法

CreateTrust("Forest1", "Forest2");

答案 1 :(得分:0)

您正在致电

 CreateTrust();
在你的if里面。 CreateTrust需要2个字符串参数。所以你需要打电话:

 CreateTrust(string1,string2); or CreateTrust("something","something");

将string1和string2替换为实际变量。