C# - With LINQ, How To Transfer A List<List<string>> To List<string>
Dec 15, 2010I got an object of List<List<string>>I need to bring this into a ist<string>I have no idea how to do this with LINQ.
View 1 RepliesI got an object of List<List<string>>I need to bring this into a ist<string>I have no idea how to do this with LINQ.
View 1 RepliesI want the Function to accept List(Of String), Array & String and similarly return List(Of String), Array & String respectively. The Function simply adds a string (month) to the input collection. I just want to use it for string, array and list with needing to think of conversions.
[Code]...
We're working on a big ASP.NETVB.NET website project. I need to populate three dropdownlists. To last two are independent of the previous ones. The population data comes from an SQL Server. I'd have no problem doing this with code-behind with post back but we don't want any PostBacks so I started to develop this in AjaxjQuery.
[Code]...
I'm trying to solve a problem regarding types of list. First of all I have a stored procedure in my DB which does a select of a single column and I try to proceed it in my app in VB. By making a method function I declared a DataTable that loads through the SqlCommand(with the CloseConnection behavior). After that I publicly declared a List(Of String) which needs to be populated with the rows/items from the stored procedure that is on the way. Below is my snippet of the code:
Dim dt As New DataTable()
Try
If conn.State = ConnectionState.Open Then
[Code]....
It's LPrefix = collection.Cast(Of String)() where I get an exception error telling me that I can't really convert it. The old fashion way is to iterate with for/for each loop but that's not what I want for best use of performance especially if the list will have thousands of rows from a single column. So basically, I want to insert those items from that DataTable to the List(Of String) without For/For Each loop.
Running on VisualStudio2010 Ultimate, .NET FrameWork 4.0.
I have this vb code in my asp.net webservice.
<WebMethod()> _
Public Function GetUsers(ByVal prefixText As String, ByVal count As Integer) As String()
Dim UsersList As New List(Of String)
[code]....
However, This returns all the users from my user table. I want to get just the users where the fullname is like the prefixtext variable that is passed in to the function.Now I need to use LINQ(the only way I can think of). But how do I change my code.
Is it wrong? Please suggest me correct way.
Public Function ReadXML() As List(Of String)
Dim list As New List(Of String)
Dim xmlDoc As XDocument = XDocument.Load("C:\MappingFile.xml")
[code].....
I figure I should use 'Aggregate' but apparently I am getting it wrong First I get a list of my Entity objects Dim employers As List(Of myEntity) = (New XXXX()).getZZZ(userName, userType) Then I figured this would be a way to put all the names in a string Dim names as String = employers.Aggregate(Function(current, [next]) current.Name & " " & [next].Name)
[Code]....
I am using a path comparison to find any children tags which works well when there is only 1 tag selected. This is my code for when multiples tags are selected but it is not working. Can you point me in the right direction?
Single Tag Selection (working)
Dim tagpath = uxTags.SelectedItem.Text
lnqCases = From i In lnqCases Where i.HelpDeskTagItems.Any(Function(x)
[code]...
Is there a way to check if a column contains all or any of an items in a list? Example "ABCDEFG" is my column value. "A" "C" "L" is my list stored in a list. I need to find rows that contains at least one item in my list. Then items that contains ALL the items in my list (a basic OR / AND search such as a SE would have)
View 1 RepliesI have the following code:
[code]...
The intention is to convert an IList of custom objects to a string equivalent comprising each element in the Ilist. Unfortunately I can't seem to find a way to get the underlying data of the custom object, and of course as in the above example, using object simply gives me a string of types definitions, rather than access to the underlying data.
I want to reorder a list of strings into a different list of strings. I am creating multiple loops to do this, however i was wondering if there was a better way to do this.
Dim values As New List(Of String)
For Each val As String In vals
If val.Contains("10") And val.Contains("Year 1") Then
[Code]....
There are going to be quite a lot of these loops to do what I want can anyone offer any help or a better way to go about doing this? Note that I want the values list to return 10,10,10,20,20,20 so that lines that have 10 should be added first and lines with 20 then afterwards.
y have this class
Private Class MyClass
Public Property propertyOne() as String
Public Property propertyTwo() as String
[code].....
I have two List(Of String) both containing several hundred thousand results.
Private Function AddUniqueFiles(lNewFiles as List(Of String)) As outList(Of String)
Dim aCounter As Integer = 0
Dim files As New inList(Of String)
[Code]....
However the time it takes to do this comparison can be very long indeed - is there a better way of doing this type of comparison... All I am trying to do is add values from List2 in to List1 which are not already present in List1 - So in effect adding new Unique values found in List 2 in to List 1. I am only looking for performance improvements - nothing else.
How can I get a new distinct list from an existing list using LINQ? This is what I have so far and it is not distinct but does give me a new list.
Dim tmpQryColumn = (From a In _allAudits
Select New CheckBoxListItem
With {.Id = a.AuditColumn, .Name = a.AuditColumn}
).Distinct()
_columnList = New List(Of CheckBoxListItem)(tmpQryColumn)
I have 2 classes
Public Class Shipper
Public Property ShipperID As Long
Public Property CreateDate As DateTime
[Code].....
How can I get a new distinct list from an existing list using LINQ? This is what I have so far and it is not distinct but does give me a new list.
Dim tmpQryColumn = (From a In _allAudits
Select New CheckBoxListItem
With {.Id = a.AuditColumn, .Name = a.AuditColumn}
[code]......
I have two generic lists, named ListA and ListB. Both ListA and ListB could potentially have duplicate items. What I would like to do is use LINQ to grab the items in ListB that are not in ListA, but I'm unsure how to do so.
View 8 RepliesI'm trying to create a list of days(integer) from a list of dates(date).
I tryed to do this....
[Code]...
This is what I want to do as seen in C#(loop against a list and fill another list from its data using Linq)
[Code]...
I am writing app in vb.net
I have two variables one with list of RoomRate and other with list of RoomTypes.
We have RoomRates and RoomTypes linked with RoomTypeInfo variable insite the RoomRate.
So how do i find the RoomTypes which donot have the RoomRates Defined.
My Sample Code:
class RoomType
property UIN as integer
property Title as string
end class
[Code]......
I'm basically brand new to LINQ. I've seen some examples that allow me to strong type objects using LINQ but I don't really understand them because they're in C#, which I guess lets you do different things with LINQ(I think?). [Code] I just want to get a list of all the products from the XML doc and put them into a Generics list.
View 3 RepliesI have a List(of String()). I have written a custom comparer (implements IComparer(of string)) to do an alphanumeric sort.Is there a way to sort the List using a given index to determine which position in the String() to sort by? In other words one time I might sort by Index = 0 and another time by Index = 3. The length of all String() in the list is the same.For reference this question is similar to Sort List<String[]> except I am using VB.net and that question is hardwired to Index=0.
EDIT from OP's comments:I started simple with the non custom comparer but I am getting an error: expression does not produce a value. Not sure what I am doing wrong.Here is the code:
Public Shared Function SortListOfStringArray(ByVal ListOfStringArray As List(Of String()), ByVal SortByIndex As Integer) As List(Of String())
Return ListOfStringArray.Sort(Function(x, y) x(SortByIndex).CompareTo(y(SortByIndex)))
End Function
Whats the best way to convert a list(of string) to a string with the values seperated by ,
View 3 RepliesI need to get a string from an items collection in a list box on one form to a list box on another form in VB 2008. Here is the code (I've tried a couple ways in the code to get the values over).
Public Class frmPrintBooks
Private Sub btnClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles btnClose.Click
[Code]....
Dim namelist As List(Of String) = New List(Of String)
namelist.Add("Hi")
namelist.Add("Hello")
[code].....
I am trying to declare List(Of String(2)) and it doesn't work
I understood that if I specify the length of the string() the compiler will not need to guess the length and it will be more fast that way, is it correct?
I have a list with a few items ( changes once in a while ) named itemlist
[Code]...
I'm thinking about making a queue system for my program which uses Asynchronous file downloading.
Now what I'd like to know is if I setup a For Loop like so[code]...
And I add to that list while the program is looping through this, will the program pick up that new Item, or do I need to find a way to abort and restart?
I was wondering how to add the text from a text file to a List(Of String), one line per item (in the list).
View 19 RepliesI was wondering how I could go about getting a list of string from a list of objects, while removing duplicates[code]....
View 2 Replies