简体   繁体   English

尝试在if语句中调用方法,但出现错误CS7036

[英]Trying to call a method in an if statement but i am getting an error CS7036

I am trying to call my method in a if statement but I am receiving a error CS7036 There is no argument given that corresponds to the required formal parameter 'sourceForestName' of 'FixTheDomain.CreateTrust(string, string)' 我试图在if语句中调用我的方法,但收到错误CS7036没有给出与“ FixTheDomain.CreateTrust(string,string)”的所需形式参数“ sourceForestName”相对应的参数

This is the method im calling 这是即时通讯方法

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);

Here is where im calling it 我在这里叫它

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

    }

Im really not grasping where it wants me to get those parameters from in my if. 我真的没有把握要我从if中获取那些参数的地方。

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

CreateTrust("Forest1", "Forest2");

You are calling 你在打电话

 CreateTrust();

inside of your if. 如果你的内心。 CreateTrust requires 2 string parameters. CreateTrust需要2个字符串参数。 So you need to call: 因此,您需要致电:

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

replace string1 and string2 with actual variables. 用实际变量替换string1和string2。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM