我想創建一個通用圖像上傳函數,因此我可以將它用於包含FileContent,FileName和FileType的不同屬性名稱的不同類。爲各種類型設置傳遞參數的值c#
這是我到目前爲止所嘗試的,但顯然這是行不通的,因爲它沒有設置傳遞參數的值。
public static void StoreFile(this HttpRequestBase @this, byte[] fileContent, string fileName, string fileType)
{
if ((@this.Files != null) && (@this.Files.Count == 1))
{
var file = @this.Files[0];
if ((file != null) && (file.ContentLength > 0))
{
var content = new byte[file.ContentLength];
file.InputStream.Read(content, 0, file.ContentLength);
fileContent = content;
fileName = file.FileName;
fileType = file.ContentType;
}
}
}
是否有任何方式傳遞匿名類型或在這種情況下會有所幫助?
你是說你想要的'StoreFile'方法實際修改給出這樣參數的值他們可以在其他地方使用? – ThePerplexedOne
@ThePerplexedOne確實。 –
有關**傳遞引用**和**傳遞值**的更多信息,請參見此線程:http://stackoverflow.com/questions/555471/modify-method-parameter-within-method-or-return-結果 – ThePerplexedOne