我收到错误CS1501:方法'关闭'没有重载需要'0'参数 [英] I am getting error CS1501: No overload for method 'Close' takes '0' arguments

查看:398
本文介绍了我收到错误CS1501:方法'关闭'没有重载需要'0'参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

try
        {
            // Grab Text From Image
            MODI.Document ModiObj = new MODI.Document();
            ModiObj.Create(ImagePath);
            ModiObj.OCR(MODI.MiLANGUAGES.miLANG_ENGLISH, true, true);

            //Retrieve the text gathered from the image
            MODI.Image ModiImageObj = (MODI.Image)ModiObj.Images[0];

            // Store Image Content in Text File
            FileStream CreateFileObj = new FileStream(HttpContext.Current.Request.PhysicalApplicationPath + @"convertedFile\OCR_File.txt", FileMode.Create);


            //save the image text in the text file 
            StreamWriter WriteFileObj = new StreamWriter(CreateFileObj);

            WriteFileObj.Write(ModiImageObj.Layout.Text);

            //WriteFileObj.Write(xyz);

            WriteFileObj.Close();

            ModiObj.Close();
        }
        catch (Exception ex)
        {
            throw new Exception(ex.Message);
        }
    }



我收到错误CS1501:方法'关闭'没有重载需要'0'参数


I am getting error CS1501: No overload for method 'Close' takes '0' arguments

推荐答案

对文件操作使用'using'语句。您不需要显式调用flush和close方法。它们将被自动调用。

Do use 'using' statement with file operations. You don't need to explicitly call flush and close methods. They will be called automatically.
try
{

// Grab Text From Image
MODI.Document ModiObj = new MODI.Document();
ModiObj.Create(ImagePath);
ModiObj.OCR(MODI.MiLANGUAGES.miLANG_ENGLISH, true, true);

//Retrieve the text gathered from the image
MODI.Image ModiImageObj = (MODI.Image)ModiObj.Images[0];

// Store Image Content in Text File
using(FileStream CreateFileObj = new FileStream(HttpContext.Current.Request.PhysicalApplicationPath + @"convertedFile\OCR_File.txt", FileMode.Create))
using(StreamWriter WriteFileObj = new StreamWriter(CreateFileObj))
{
WriteFileObj.Write(ModiImageObj.Layout.Text);

//WriteFileObj.Write(xyz);

}
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
}


看起来你必须传递'可选'(参见这里 [ ^ ] :-))<$ c的参数$ c> MODI.Document.Close 方法。



所以改为

It looks you have to pass the 'optional' (see here[^] :-) ) argument to the MODI.Document.Close method.

So change from
引用:

ModiObj.Close();

ModiObj.Close();




to

ModiObj.Close(false);



(或 ModiObj.Close(true); ,取决于你的需要。)


(or ModiObj.Close(true);, depending on your needs).


当你将不同的参数传递给带有不同参数的方法时,会显示这种错误。

For Ex ...

This kind of error shown when you are passing different no of arguments to method that takes different no of argument.
For Ex...
public void MyMethod(string name)
{
   //you have to pass one argument whenever you call this method. 
}

//You have to call it like...
MyMethod(StringValue);
//Following will give error.
MyMethod(); // error.
MyMethod(intValue) // error
MyMethod(stringValue, StringValue) // error



或者您可以在方法参数中使用可选参数


or you can use optional parameter in method argument

public void MyMethod(string name="DefaultValue")
{
   //Here if you don't pass any argument then it will take default value and it won't throw error any more
}





抱歉说这个,但我不能阻止自己评论,





sorry for saying this but i can't stop myself from commenting,

"ModiObj.Create(ImagePath);"



真的! Modi 这是着名的,人们在他们的代码中使用他的名字。



只是开玩笑。不认真对待它。



希望这个帮助

-----------------

Pratik Bhuva


Really !!! Modi is this famous that people are using his name in their code.

just kidding.don't take it seriously.

Hope This Help
-----------------
Pratik Bhuva


这篇关于我收到错误CS1501:方法'关闭'没有重载需要'0'参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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