开发者

Sending A File As A Method Argument?

Is this sort of thing possible:

public static void DoThis(file aFile){
    //Blah blah blah
开发者_开发知识库}


It depends what you need to do with it :)

Options include:

  • path (string)
  • contents (string or byte[])
  • some complex object model (od your own choosing) of the contents
  • FileInfo
  • FileStream (or just Stream)
  • some kind of reader/writer; TextReader, XmlWriter etc


Absolutely. If you have the file reference in the calling method, then you can definitely do that.


What you can pass is the handle to the file i.e. reference to the file object or its contant in Binary or text format. The file object represents the handler to file and not the actual file.


Yep, you can certainly do that. just remember to check for nulls....

public static void DoThis(file aFile)
{
    if ( aFile == null ) { // report error or whatever }
    //Blah blah blah
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜