static class Extension
{
public static void ForEach<T>(this IEnumerable<T> source, Action<T> action)
{
foreach (var x in source)
{
action(x);
}
} public static System.Data.DataTable SelectWith(this DataTable sourceTable, Predicate<DataRow> predicateCondition)
{
DataTable resultTable = sourceTable.Clone();
sourceTable.Rows.OfType<DataRow>().Where(s => predicateCondition(s)).ForEach(s => resultTable.ImportRow(s)); return resultTable;
}
}如何用VB.NET改写?
我试着改写了一下,如下,但是总是在编译的时候出现一个 Expression does not produce a value. 的错误,该如何改正?多谢Imports System
Imports System.Runtime.CompilerServices
Imports System.DataPublic Module Extension
<Extension()> _
Public Sub ForEach(Of T)(ByVal source As IEnumerable(Of T), ByVal action As Action(Of T))
For Each x In source
action(x)
Next
End Sub <Extension()> _
Public Function SelectWith(ByVal dt As DataTable, ByVal predicateCondition As Predicate(Of DataRow)) As DataTable
Dim resultTable As New DataTable()
resultTable = dt.Clone()
dt.Rows.OfType(Of DataRow).Where(Function(row) predicateCondition(row)).ForEach(Function(row) resultTable.ImportRow(row)) Return resultTable
End Function
End Module
{
public static void ForEach<T>(this IEnumerable<T> source, Action<T> action)
{
foreach (var x in source)
{
action(x);
}
} public static System.Data.DataTable SelectWith(this DataTable sourceTable, Predicate<DataRow> predicateCondition)
{
DataTable resultTable = sourceTable.Clone();
sourceTable.Rows.OfType<DataRow>().Where(s => predicateCondition(s)).ForEach(s => resultTable.ImportRow(s)); return resultTable;
}
}如何用VB.NET改写?
我试着改写了一下,如下,但是总是在编译的时候出现一个 Expression does not produce a value. 的错误,该如何改正?多谢Imports System
Imports System.Runtime.CompilerServices
Imports System.DataPublic Module Extension
<Extension()> _
Public Sub ForEach(Of T)(ByVal source As IEnumerable(Of T), ByVal action As Action(Of T))
For Each x In source
action(x)
Next
End Sub <Extension()> _
Public Function SelectWith(ByVal dt As DataTable, ByVal predicateCondition As Predicate(Of DataRow)) As DataTable
Dim resultTable As New DataTable()
resultTable = dt.Clone()
dt.Rows.OfType(Of DataRow).Where(Function(row) predicateCondition(row)).ForEach(Function(row) resultTable.ImportRow(row)) Return resultTable
End Function
End Module
解决方案 »
- WPF如何在style中添加trigger?改变圆形按钮的背景色
- 按钮实现Panel的左右移动,求大神帮忙看一下
- winform 获取服务器端数据时如何显示正在加载..
- C# 操作图片相关
- C#中调用Oracle存储过程
- 急急急...C#实现鼠标手势关闭功能和最小化
- DataGrid:怎样设置不可添加新行,但可以编辑某些列
- 【提问100分】请问,如何在WEB页面中使用C/S的界面。
- vs2003如何C#链接sql server 2008?
- 请问这个可以反编译获得原代码和窗体控件吗?
- WPF WINDOWS MEDIAELEMENT 的问题
- WPF中RichTextBox在DATAGRID中如何绑定数据
试试这个网站
http://www.developerfusion.com/tools/convert/vb-to-csharp/