在使用匿名类型时,我发现了GroupBy在C#和VB.net中的结果不同。具体来说,当任何键都是可空类型且没有值集时,VB.net似乎无法正确地对项进行分组。
假设我有以下模型和一些数据:
public class Record
{
public int? RecordTypeId { get; set; }
public int? PlayerId { get; set; }
public int? TeamId { get; set; }
public int? Salary { get; set; }
几周来我一直在为这件事苦苦挣扎。我似乎可以在C#中找到答案,但找不到vb.net,因为VB.net使用匿名类型。我可以分组我的专栏,但我只想要短日期(11/11/11),而不是日期和时间(11/11/11 : 11:11:11)。以下是我目前得到的信息:
Dim preSort = SortedTimeline.GroupBy(Function(GroupTime) New With {Key GroupTime.Scheduled_Start})
这只在时间也匹配的情况下才创建组。我不能把任何.tostring或任何日期魔术在密钥上,因为它是匿名的。
知道吗?
我试图将这个方法转换成VB.NET,但在线转换器似乎把转换搞得一团糟。有没有人可以帮忙:
C#原件:
private IEnumerable<IGrouping<string, Reference>> FindReferencesWithTheSameShortNameButDiffererntFullNames(List<Reference> references)
{
return from reference in references
group reference by
在VB.Net中,我有以下LINQ查询
Dim temp = (From r In datatable Select r Order By r.str Descending)
但是我希望基于str列,它是唯一的。我知道如何从LINQ中获取str column并将其标记为distinct。但是我想要整行(所有列),并且具有基于str列的不同
就像这样
Dim temp = (From r In datatable Select r Order By r.str Descending).distinct(r.str)
如果有人能用C#给我答案,我会用VB.Net翻译它
示例
数据表
col1 c
我在vb.net应用程序中有一个数据表。数据表如下所示:
State Level City
AL T Arlton
AL T Brton
AL T Rurton
CO T Dver
CO T Crodo
WA T Blain
WA T Bwelham
我想对状态进行分组,并执行一个循环。我尝试了以下操作,但未按预期工作。请帮帮忙
到目前为止,我尝试了以下内容:
Dim result = From r In dt Group r By state = r(0) Into Group S
我有一个List of Person类对象。
List Persons = new List();
class Person
{
public int CatId{ get; set; }
public int SubcatId{ get; set; }
}
现在,Person类的实例可能具有相同的、CatId、或SubcatId。但是,对于两个类来说,它们是不一样的,同时使得每个实例都是统一的。例如:
Person1: {CatId = 1, SubcatId = 1}
Person2: {CatId = 1, SubcatId = 2}
Person3: {CatId =
出于教育目的,我尝试将"Linq in action“一书中的以下Linq表达式转换为VB.net
原始C#
var list =
from book in SampleData.Books
group book by new { book.Publisher.Name, book.Subject }
into grouping
select new {
Publisher = grouping.Key.Publisher,
Subject = grouping.Key.Subject,
Book = grouping
};
我的尝试是
我有一个VB.NET应用程序,希望对多个列执行Group。
类结构:
Public Class Person
Public Property Name as String
Public Property City as String
Public Property Country as String
End Class
Dim oResult = PersonList _
.GroupBy(Function(v) New With {v.City, v.Country}) _
.Where(Function(gr
我需要最优雅的解决方案动态选择/分组/排序通过Linq2Entities (VB.NET/ via 2012)。
我正在尝试使用System.Linq.Dynamic库()
这个构造с工作得很好
Dim testQuery= testDB.testTable.Select("New(Field1)").GroupBy("New(Field1)", "it")
但是这个例子(这个例子在博客/SO上找到)会产生错误:
Dim testQuery= testDB.testTable.Select("New(Field1, Count())
我正在尝试将Anthyme Caillard's INotifyDataErrorInfo implementation转换为VB.NET。一切都很顺利,直到我到达Validate方法,该方法具有以下LINQ查询,其中q的类型为IEnumerable<IGrouping<string, ValidationResult>> var q = from r in validationResults
from m in r.MemberNames
group r by m into g
select g; 我尝试了以下
我有许多aspx页面在一个文件夹(100页),他们将继续增加。我有一个vb.net文件,其中有这些网页的代码。我可以从所有这些页面调用vb.net文件中的页面加载事件吗?目前我正在使用这段代码,但它没有读取页面加载事件。
<%@ Page Language="VB" %>
<script runat="server">
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
newone_load(page)
E
我必须将以下表达式从VB.NET转换为C#:
Dim z = From d In db.GPSdevice
Where d.CompanyId = currentuser.CompanyId And d.Type = "Trailer"
Order By d.ListOrder Descending
Group d By Geofence = d.GeofenceLocation Into g = Group, Count()
Order By Count Descending
我被一组一组的.
我发现,当按多个值分组时,VB.NET不能很好地工作,但是它在C#中工作得很好,下面是我的代码,我的VB.NET代码有什么问题吗?
以下是我的VB.NET代码:
Sub Main
Dim empList As New List(Of Employee)()
empList.Add(New Employee() With _
{.ID = 1, .FName = "John", .Age = 23, .Sex = "M"c})
empList.Add(New Employee() With _
{.ID = 2, .FName
我想我有两组
using System.Collections.Generic;
namespace ConsoleApplication
{
internal class Student
{
public string Name;
public string Surname;
public int Mark;
}
internal class Program
{
private static void Main()
{
var twoGroups
我正在努力找出每所大学最受欢迎的专业。
下面是表格的一个示例:
Institution Major_Name Count Major
School 1 Art 2 First
School 1 English 12 First
School 1 Math 7 First
School 1 Art 6 Second
School 1 English 4 Second
School 1 Math 3
基本上我有一个大小不同的整数数组。我需要将每个数字相互比较,并显示哪个数字是重复的。例如:
Dim ints() As Integer = {1,2,2,5,4,6}
出现多次的数字是2。
如何遍历数组并将每个整数与数组中的数字进行比较。我尝试了一个for循环,但是它没有返回我想要的值。我是VB.NET的新手,不能完全理解。
Protected Function ammountChanges(order As BasicSimpleOrder, createOrDelete As Boolean) As (change As Decimal, currency As String)
End Function
我知道这是可能的,我想了解更多。
但是,如果我在谷歌搜索
function returning multiple values vb.net
例如,
或堆叠溢出
没有人提到这种技术。
即使我在寻找
function returning multiple values through anonymous ty
我有一份名单
dim list As New List(Of Person)
‘Lets说上面的列表有6个person对象,有3种年龄类型,例如25岁,28岁,35岁
我想写一个函数,它可以生成3个按年龄分组的人对象的单独列表,并填写它们
dim masterList As New List(List(Of Person))
您能推荐一些在Vb.net中实现此功能的代码片段吗
person类的定义
class Person
Dim age as Integer
Dim name as String
End Class