转换.NET 4.0的语法OfType到.NET 3.5 [英] convert .net 4.0 syntax OfType to .net 3.5

查看:127
本文介绍了转换.NET 4.0的语法OfType到.NET 3.5的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这样的.NET 4.0 code:

I have this .NET 4.0 code:

var myTable = tables[1];
myTable = tables.Item["Table1"];
myTable = tables.OfType<Excel.ListObject>().FirstOrDefault(t => t.Name == "Table1");

我试图编译.NET 3.5和获得一堆错误:

I am trying to compile with .NET 3.5 and getting a bunch of errors:

错误23属性,索引器或事件'项目'是不支持   语言;尝试直接调用访问方法   Microsoft.Office.Interop.Excel.ListObjects.get_Item(对象)

Error 23 Property, indexer, or event 'Item' is not supported by the language; try directly calling accessor method 'Microsoft.Office.Interop.Excel.ListObjects.get_Item(object)'

错误24Microsoft.Office.Interop.Excel.ListObjects'不包含   对于OfType和最佳推广方法重载的定义   System.Linq.Queryable.OfType(System.Linq.IQueryable)有   一些无效参数

Error 24 'Microsoft.Office.Interop.Excel.ListObjects' does not contain a definition for 'OfType' and the best extension method overload 'System.Linq.Queryable.OfType(System.Linq.IQueryable)' has some invalid arguments

错误25实例参数:无法从转换   Microsoft.Office.Interop.Excel.ListObjects来   System.Linq.IQueryable

Error 25 Instance argument: cannot convert from 'Microsoft.Office.Interop.Excel.ListObjects' to 'System.Linq.IQueryable'

能否请你指导我正是这些错误的意思,这样我可以尝试将其转换为.NET 3.5?

Can you please guide me on exactly what these errors mean so that I can try to convert this to .NET 3.5?

感谢您这么多的意见。

推荐答案

这个问题指的是给出<一个答案href="http://stackoverflow.com/questions/12755248/this-command-requires-at-least-two-rows-of-source-data/12876478#comment17540673_12876478">This命令至少需要两行的源数据的;在code正显示出3个不同的code访问表/的ListObject的方式。

This question refers to an answer given for This command requires at least two rows of source data; the code is showing 3 different ways of accessing a table/listobject in code.

这是code我贴:

    var myTable = tables[1];
    var myTable = tables.Item["Table1"];
    var myTable = tables.OfType<Excel.ListObject>().FirstOrDefault(t => t.Name == "Table1");

我为了说明,有在code访问表的不同方式。

I meant to illustrate that there are different ways of accessing a table in code.

要把它在上下文中,我创建了一个按钮叫TestButton功能区。这里是整个code,应与3.5:

To put it in context, I have created a Ribbon with a single button called "TestButton". Here is the entire code, should work with 3.5:

using Excel = Microsoft.Office.Interop.Excel;


    private void TestButton_Click(object sender, RibbonControlEventArgs e)
    {
        var worksheet = (Excel.Worksheet) Globals.ThisAddIn.Application.ActiveSheet;
        var tables = worksheet.ListObjects;
        var table = tables.Item["Table1"]; // this is the line you are referring to

        //do something with table
    }

这篇关于转换.NET 4.0的语法OfType到.NET 3.5的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆