似乎无法摆脱错误C#控制台应用程序 [英] cant seem to get rid of error c# console app
本文介绍了似乎无法摆脱错误C#控制台应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在导入"部分的字符串"下出现一条摇摆不定的红色线条(在下面的代码中标记为删除线),错误为预期类,委托,枚举,接口或结构"
任何人都知道我要去哪里哪里
I get a red wiggly line under ''string'' in the Import section (marked with a strikethrough in my code below) with the error "Expected class, delegate, enum, interface, or struct"
anyone know where im going wrong
namespace MEFProgram
{
[Import (typeof(IMessage))]
public string GetMessage {get;set;}
class Program
{
static void Main(string[] args)
{
Program obj = new Program();
obj.Compose();
}
void Compose()
{
var catalog = new TypeCatalog();
var container = new CompositionContainer();
container.ComposeParts(catalog);
Console.WriteLine(GetMessage);
Console.ReadLine();
}
}
}
class plugIN
{
[Export(typeof(IMessage))]
string GiveMessage
{
get
{
return "Message Inserted by MEF";
}
}
}
推荐答案
public string GetMessage {get;set;}
不在类之内,不能在名称空间中使用getter和setter.
Is not within a class you can not have a getter ans setter in the namespace.
该属性不应该超出该类吗?只是一个猜测..
Should the attribute not go above the class ? Just a guess..
namespace MEFProgram
{
public string GetMessage {get;set;}
[Import (typeof(IMessage))]
class Program
{
这通常是由于额外的封闭形而引起的.
请参阅以下答案以获取更多信息.
预期的类,委托,枚举,接口,或struct [
This is often caused by an extra a closing paranthesis.
Refer to the below answer for more information.
Expected class,delegate,enum, interface,or struct[^]
这篇关于似乎无法摆脱错误C#控制台应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文