Lambda Function Complex List Sort

Aug 12, 2009

I'm trying to sort a list of string, which (each item) consists of a word followed by a space, then a number. I want to sort first alphabetically by the word, then numerically by the number. I tried something like this:
wordList = wordList.OrderBy(Function(x, y) CStr(x.Split(" "c)(0)).CompareTo(CStr(y.Split(" "c)(0)))).ThenBy(CInt(x.Split(" "c)(1)).CompareTo(CInt(y.Split(" "c)(1))))

View 5 Replies


ADVERTISEMENT

Lambda Tutorial And Solving A Lambda-Function

Dec 14, 2009

Is it possible to shorten the following function to a lambda expression?Or (to do the trick by myself) what is the best and most understandable for beginners tutorial for lambda in vb.net?[code]

View 2 Replies

.net - Use List.Sort And Comparision(of T) To Sort Descending/Ascending?

Jul 5, 2011

I have a MyObject; myObjects as List(Of MyObject) and a delegate Comparison(Of MyObject) that uses a lot of comparison functions (ByA, ByB, ByC etc) Ã la:

Shared Function CompareMyObjectsByName(x As MyObject, y As MyObject) As Integer
Return x.Name.CompareTo(y.Name)
End Function

[Code].....

View 2 Replies

Convert C# Lambda Function To .net?

Oct 6, 2011

I have this function that maps a IDataReader to a class. It is obviously written in C#. My co-worker wants to use the same method in his code, but he is writing in VB.net. Basically I am having difficulty rewriting this due to the Lambda expressions used in C#. He is running .Net 3.5.

[Code]...

View 3 Replies

Wrap Sub As Function For Use In Lambda?

Mar 25, 2010

I have a problem with VB9 and Moq.I need to call a verify on a Sub. Like so:logger.Verify(Function(x) x.Log, Times.AtLeastOnce)And my logger looks like this:

Public Interface ILogger
Sub Log()
End Interface

[code].....

View 2 Replies

Use A Function Both Directly And As A Lambda Expression?

Apr 24, 2012

Should I be concerned about the performance of the Compile method here?[code]...

The reason I want the lambda expression is because I want that function to be able to get all the way through LINQ-to-SQL to be converted to SQL. The reason I want the direct version is because I have other code that I want to validate individual serial numbers before submitting changes. And I fear that GetValidSerialNumbers.Contains(serialNumber) will execute a more-complex-than-necesssary query.

View 1 Replies

List(Of T).Sort - Sort The List By Year

Jul 10, 2011

I have a List(Of T) storing a list of Custom classes called Advertisement. Each advertisement contains 3 properties, Year, Make and Model. I need to sort the list By Year, then by Make and then by Model. I have a property in the Advertisement class called Vehicle which returns a formatted string with the Year Make Model like 2007 Toyota Tacoma and ive been sorting on that but its not working how I thought it would. Basically I want to sort the list by Year (decending; lowest year first) then sort by the Make and Model (in alphabetical order) Is that even possible? Here is the code ive been using.

[Code]...

View 8 Replies

Pass A Lambda Function To Linq's Orderby?

Jan 24, 2010

I am trying to pass a lambda function to Linq's orderby and cannot get it to work.

The relevant code is:

Dim myordering = Function(m) m.Count
If isAlphaOrder Then
myOrdering = Function(m) m.Key 'Order by Alphabet

[Code].....

View 4 Replies

Why Does Setting A Property With A Lambda Function Fail

Mar 31, 2009

I have a lambda function that I can assign to a field and pass it to a sub routine, but cannot assign to a property. My field is defined as follows:

Public Delegate Sub SubDelegate()
Private pDeleteFunction As Func(Of BookCaseRow, SubDelegate)

[code].....

View 3 Replies

Asp.net - Reference Property Of An Unknown Type In Lambda Function

May 18, 2011

I'm trying to create a generic function to build a Linq expression from a list of Telerik grid filters. I'm trying to stay clear of dynamic Linq. Because I don't know the type that I'm building the expression for, I'm attempting to use reflection in the lambda functions to refer to a property, but after applying the fix suggested by @JaredPar I get the error, "The LINQ expression node type 'Invoke' is not supported in LINQ to Entities." Is there any way around this? here is my code:

Public Shared Function buildRadFilter(Of T)(ByVal filterExpression As List(Of GridFilterExpression)) As Expressions.Expression(Of Func(Of T, Boolean))
Dim returnPred = PredicateBuilder.True(Of T)()

[Code]....

View 1 Replies

Convert An Existing Lambda Function Written In C# To Program?

Mar 29, 2010

I have the below C# Lambda function and I need to convert it to a VB.Net code. I tried many times but I couldn't convert it the right way. [code]...

View 10 Replies

Syntax For Using List.FindAll() With A Lambda?

Sep 1, 2011

In C# I have been performing a FindAll in a generic list as follows:List<group.category> tlist = list.FindAll(p => p.parid == titem.catid);Two questions, is this the appropriate way of performing such a thing and how do I convert this to VB.Net

View 1 Replies

VS 2005 Sort List Of Objects By Child List Order?

Jul 20, 2011

I'm having a bit of a 'brain doner' moment here

I have a list of Objects. Each of these Objects contains a list of other Objects (pseudo code) :-

Private Structure Object1
dim Name as string
dim ListOfObject2 as List(Of Object2)

[Code]....

I need to sort the list of Object1 by the Value in Object2. I have a comparison class which sorts Object2 by its Value nicely.

View 13 Replies

Nested Multi-line Lambda Function As Parameter For LINQ Select Is Causing An Error

Jun 29, 2010

I'm trying to use a nested multi-line lambda Function in VB.NET and am getting an error. Here's what my code looks like:

cartItems = cartItems.Select(Function(ci) New With {.CartItem = ci, .Discount = discountItems.FirstOrDefault(Function(di) di.SKU = ci.SKU)})
.Select(Function(k)
If k.Discount Is Not Nothing Then

[code]....

View 2 Replies

.net - Sort Generic List Based Upon A Different List?

Oct 29, 2010

What would be the fastest way to sort a list that contains a list of objects, based upon another list? An example follows:Say I have multiple lists of employees. Each individual list has a common property value, say "Department". So I have a list of employees, in one list they all have the department string value of "Sales". In another list all the objects have a department value of "Finance". These lists of employees are then contained in a list which holds them all.

I have a second list, which should drives the sort order of the employee lists. The second list simply contains a list of strings like, "Finance", "Sales", "IT" and so on. I'd like my lists of customers to be sorted in the order of "Finance", "Sales", etc.I'm using VB.NET in .NET 2.0

View 1 Replies

Lambda Coding - Basic Code Of Lambda With Explanation

Jun 21, 2011

Im hearing about this, can someone explain it to me or please show some basic code of Lambda with explanation.

View 2 Replies

Using The Array Type .Sort Function To Sort An Array?

Mar 1, 2010

I am using the Array type .Sort function to sort my array.By default it places the result Array into Ascending order Least to Greatest How do I change that to Descending order Greatest to Least?and How do I change it to Closest to logic? or does that not exist?Assume there is an Array of Numbers 0,13,21,-2,4,5,1.34 and I want them to sort closest to 0 or some other arbitray value; the Output should look similar to:

0,1.34,-2,4,5,13,21

View 19 Replies

Disabling Sort Function In Datagridview>

May 16, 2006

Is it possible to disable the "sort function" in datagridview that happens when pressing the header?

I would like display some data that you cant order by clicking on the columheader. Can you lock the headers somehow?

View 5 Replies

Implement A Sort Function In My Program?

Jan 25, 2010

I'm looking to implement a sort function in my program however I am new to VB and don't know how to. Basically I have 6 objects in my program racing across the screen and what I would like is a leaderboard showing the current top 3.

View 13 Replies

How To Sort List Of Datarow

Aug 5, 2011

i have a list of datarows. each row is having mutiple columns like userid,date,flag,etc.i want to sort the based on date. how can i do that ?

my code is:

Dim
listOfRows As
New List(Of
DataRow)()

[code]....

i want to sort the listOfRows in ascending order of date which is a column in a row?

View 4 Replies

Sort A List Of Word?

Sep 30, 2011

i wrote the following code to sort a list of word:

Public Class Sort_DT
Public Sub Words(ByVal index As Short, ByVal Incoming(,,) As String, ByVal Level As Integer)

[code]....

when words sorted, application used over 300 MB of memory;

View 14 Replies

Sort An Array List?

May 27, 2009

I'm trying to sort an arraylist the code is below.

the value.sort() is returning the following error - Failed to compare two elements in the array. At least one object must implement IComparable."[code]...

View 2 Replies

Sort Items In A List Box?

Apr 6, 2010

I am trying to sort items in a list box. It sorts all the numbers but one and i can't figure out why. I will post my code below. The last number is on the bottom when it is entered into the list box every time regardless of its size.

Dim sortformat As String = "{0,-10}{1,12}"
Dim w As String
Dim y As String
For x = 0 To 7

[code]....

View 3 Replies

.net - Sort Generic List On Two Or More Values?

May 15, 2009

We have a generic List(Of Product) that must be sorted on two or more properties of the Product class.

The product class has the properties "Popular" numeric (asc), "Clicked" numeric (desc), "Name" string (asc). In order of naming the properties we want the list to sort.

How can it be sort with an lamba statement? If have found to sort the list based on one property.

View 4 Replies

.net - Sort List Where Object IsNot Nothing?

Mar 2, 2011

I am trying to sort a list of classes, and I need the classes with a subclass that isnot nothing first in the list. I thought the following would work but it doesnt.ListOfClasses.Sort(Function(x, y) If(x.SubClass IsNot Nothing, 1, 0)

View 3 Replies

How To Sort Items In List View

Apr 5, 2012

i used the sorting method at msdn but it isnt nice. it sorts in string format like 1,11,12,2,21,23,3,31,32 etc. is there any other sorting method.

View 3 Replies

How To Sort Just Part Of A Huge List Using .NET

Mar 8, 2010

In .NET, the Generics Lists have a sort function that accepts IComparer or Comparison. I'd like to sort just part of a list. Hopefully I can specify the start index, count of elements to sort, and a lambda function. It looks like you can only use lambda functions to do this if you're sorting the entire list. Is that right or did I miss something?

View 4 Replies

How To Sort Multiple Column Of A List

Apr 15, 2009

I have a class for example:

Public Class Employee
Private mName As String
Private mSalary As Double

[Code].....

View 6 Replies

List.Sort Not Quite Working With Strings?

Feb 13, 2011

This is my first time posting here although I have been lurking for quite some time. I'm stuck with a problem I have seen before and never solved: I have a long list (~23,000) of alphanumeric strings that I'm reading into a List(of String) from a text file, and then sorting. When I iterate through the list after sorting, it appears to be correctly sorted EXCEPT that the element that was originally at the beginning of the list is now at the end (and it should be somewhere in the middle after the sort)Here is a sample input:

PRE1-PRE2_00015648
PRE1-PRE2_00015649
PRE1-PRE2_00015650

[code].....

View 5 Replies

Sort A List (Of String) Alphanumerically?

Apr 26, 2012

I have looked, unsuccessfully, for how to sort a list of strings alpha numerically. The .Sort() method sorts it like so:

abc,abc1,abc11,abc12,abc2,abc21,abc22

I don't want it sorted that way, I want it sorted like so:

abc,abc1,abc2,abc11,abc12,abc21,abc22

View 1 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved