c# - Method Produces --> 扩展方法必须定义在非泛型静态类中
问题描述
每当我输入这个方法
private Stream createstream(this System.Drawing.Image image, ImageFormat format)
{
var stream = new System.IO.MemoryStream();
image.Save(stream, format);
stream.Position = 0;
return stream;
}
我不断得到
扩展方法必须在非泛型静态类中定义
据我所知,我没有扩展任何东西。请指教
解决方案
编译器认为您正在尝试编写扩展方法。扩展方法:
- 是静态方法
- 第一个参数
this
在它的开头 - 在非泛型静态类中定义
编译器this
在您的 中看到this System.Drawing.Image image
,认为您正在尝试编写扩展方法,并抱怨您没有遇到第 3 点。
如果您不打算编写扩展方法,请删除this
from this System.Drawing.Image image
。
推荐阅读
- php - Wordpress 儿童主题问题
- java - 在 Spring Data Rest 中返回纯 JSON
- excel - vba代码从firefox获取数据并粘贴到excel中
- python - 如何在 python 中从 Elasticsearch 访问索引值
- c# - Roslyn 使用 SyntaxGenerator 声明局部变量
- selenium - 如何禁用插件中的首次运行页面 - selenium - firefox - java
- extjs - Ext.tab.Panel 和自动换行
- php - 多重上传功能不会向服务器发送很多文件
- python - 如何解决 Python 3 包问题
- javascript - 如何让wordpress标签输入框按回车键添加标签?