问题描述
我学习的插件能够使用的架构托管扩展性框架(MEF)
我在网上看到的示例代码,但是当我试图实现它我被困在一个点上。
I am learning plug able architecture in .Net using Managed Extensibility Framework (MEF.)I saw sample code on the net, but when I tried to implement it I got stuck at one point.
中的代码是使用:
var catalog = new AttributedAssemblyPartCatalog(Assembly.GetExecutingAssembly());
var container = new CompositionContainer(catalog.CreateResolver());
这 VAR
可在C#3.0哪里因为我编码在C#2.0。
This var
is available on C# 3.0 where as I am coding in C# 2.0.
什么是上述两种说法的选择吗?我怎样才能使他们的工作在C#2.0中使用VS 2005?
What is the alternative of above two statements? How can I make them work in c# 2.0 using VS 2005?
我想这bt后的现在说
错误1 类型或命名空间名称'AttributedAssemblyPartCatalog'找不到(是否缺少using指令或程序集引用?) C:\Documents和Settings\test\Desktop\MEFDemo\MEFDemo\Program.cs 31 13 MEFDemo
Error 1 The type or namespace name 'AttributedAssemblyPartCatalog' could not be found (are you missing a using directive or an assembly reference?) C:\Documents and Settings\test\Desktop\MEFDemo\MEFDemo\Program.cs 31 13 MEFDemo
在这里,因为我已经添加到全球化志愿服务青年SystemComponentModel.Composition
where as i have added referance to SystemComponentModel.Composition
推荐答案
这是在C#3.0中使用类型推断的。
This is the use of type inference in C# 3.0.
当使用关键字
var
在C#3.0编译器推断类型。请参见
in c# 3.0 the compiler infers the type. See scott guthries explanation
在C#2.0中,你必须声明变量类型同C#1.1
In c# 2.0 you have to declare the type of the variable the same as c# 1.1
例如
Type variableName = new Type();
让你上面的代码示例
Making you above code example
AttributedAssemblyPartCatalog catalog = new AttributedAssemblyPartCatalog(Assembly.GetExecutingAssembly());
CompositionContainer container = new CompositionContainer(catalog.CreateResolver());
心连心
HTH
这篇关于在C#3.0,我们使用" VAR"什么是它在C#2.0的替代?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!