[英]Add function to built-in class using inheritance
我試圖將自己編寫的IsImage屬性添加到HttpPostedFile類中,以便如果用戶正在上傳文件,則可以執行以下操作:
FileUpload1.PostedFile.IsImage
如何在C#中做到這一點?
您可以為此使用擴展方法 。
public static class HttpPostedFileExtension
{
public static bool IsImage(this HttpPostedFile file)
{
/*your method code goes here*/
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.