I want to turn the follow function into a Lamda. After working on it for 45 minutes, I decided to go old school. How would one do this with a Lamda?
public static void NotIn<T>(List<T> inListOne, List<T> notInListTwo,ref List<T> resultList)
{
resultList = new List<T>();
foreach (T item in inListOne)
{
if (notInListTw...
A quick brain teaser: given a string
This is a string with repeating spaces
What would be the LINQ expressing to end up with
This is a string with repeating spaces
Thanks!
For reference, here's one non-LINQ way:
private static IEnumerable<char> RemoveRepeatingSpaces(IEnumerable<char> text)
{
bool isSpace = false;
foreach ...
I want to develop an app for Windows 7 phone. It will be a GRE vocab app. i dont want to use SQL CE, my app will have 3 tables conceptually. I will be using Linq to SQL to querying data. Now i am confuse how should i store data so it is easy for retrival and update.
XML , CSV , XML or any other format ?
...
var emp = from c in root.Descendants("Objects") // From Xml XDocument
select new
{
ObjType = (string)c.Element("ObjectType").Value, //Employee object
ID = (string)c.Element("ObjectID").Attribute("ID").Value
...
I have some code that creates a list of lists. The list is of this type:
List<List<Device>> GroupedDeviceList = new List<List<Device>>();
But need to return the result in the following type:
IEnumerable<IGrouping<object, Device>>
Is this possible via a cast etc or should I be using a different definition for my list of lists?
...
We have an entity with DateTime property DateDestroyed. A query needs to return results where this value is between nullable DateTimes startDate and endDate.
The where clauses I have are:
.Where(x => startDate.HasValue ? startDate <= x.DateDestroyed : true)
.Where(x => endDate.HasValue ? x.DateDestroyed <= endDate : true);
The query ...
How can I clean up this LINQ Query to use SelectMany in the sql syntax, instead of method chaining at the end like I have done?
var runPeakWidths =
(from ipa in runAnalysis.PassAnalyses
let peakWidths = BuildPeakWidths(ipa)
select peakWidths)
.SelectMany(data => data);
Edit:
Turned into a tight little method:
...
With extension methods, we can write handy LINQ operators which solve generic problems.
I want to hear which methods or overloads you are missing in the System.Linq namespace and how you implemented them.
Clean and elegant implementations, maybe using existing methods, are preferred.
...
List<string> nameSpaceSuffixes = GetSuffixes();
foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies())
{
foreach(var suffix in nameSpaceSuffixes)
{
if (assembly.GetName().Name.EndsWith(suffix))
Register(container, assembly, suffix);
}
}
...
Hi all.
Im using Linq - objects and I need to do an update. I've been looked around for a while but not really found anything that matches.
So for arguments sake I have 2 simple List's, both with a key so I can use join happily.
I cant find a simple way to update results from obj2 into obj1.
for simple updates I'm currently doing thi...
I have a piece of code for some validation logic, which in generalized for goes like this:
private bool AllItemsAreSatisfactoryV1(IEnumerable<Source> collection)
{
foreach(var foo in collection)
{
Target target = SomeFancyLookup(foo);
if (!target.Satisfactory)
{
return false;
}
}
...
I'm writing something in the flavour of Enumerable.Where in that takes a predicate of the form Func<T, bool>. If the underlying T implements INotifyPropertyChanged, I'd like to be a bit more intelligent about re-evaluating the predicate.
I'm thinking about changing it to use Expression<Func<T, bool>>, and then using the expression tree ...
public readonly IEnumerable<string> PeriodToSelect = new string[] { "MONTH" };
var dataCollection = from p in somedata
from h in p.somemoredate
where h.Year > (DateTime.Now.Year - 2)
where PeriodToSelect.Contains(h.TimePeriod)
select new
{
p.Currency,
h.Year.Month, h.Value ...
I have an audit table which stores audit rows for a long running process at an individual task level in SQL Server.
auditId int,
TaskName nvarchar(255),
StartTime datetime,
EndTime (datetime, null),
Status (nvarchar(255), null)
The process contains parent and child steps and each step is logged to the audit table. A task may or ma...
I accept both C# and VB.NET suggestion, even though I'm writing an app in VB.NET
I have two lists of intergers
List1 {1,2,3,5}
List2 {2,4,6,7}
I want to have new List3 {4,6,7} which is composed of elements of List2 that are not in List1. I know I can write a nice For Each loop for this but I want it done in LINQ
I've been lookin...
public class ReplacementService : IReplacementService
{
public List<int> GetTeamReplacementWeight(int iTeamId)
{
IEnumerable<TeamReplacementGroup> groups = TeamReplacementGroup.GetTeamGroups(iTeamId);
List<int> weights= groups
.Select(group => group.GetWeight())
.AsParallel()
.T...
Some long-gone developer left the following LINQ query behind with no documentation and I'm struggling to understand what it does (and therefore if it's doing it right). Can someone help translate this, either by breaking it into pieces or providing the SQL equivalent?
Dim matches = From mc In mcs _
Join ri In r.Items On ...
Hi
I have a problem trying to figure out a LINQ query for the following.
The columns are MeterSerialNumber, Date, DeviceType (M or C), and then 48 reading value columns.
Some meters will have a corrector fitted. For these meters there will be both an M (DeviceType) row and a C row for the same date. I need just the C rows for these me...
I have a datatable containing 10 columns. I want to select only two columns of them.
I am not able to do it using SelectMany Extension Method.
I know how to get it from Linq To DataSet but trying using this extension method.
...
I have an XML in this format which is mapped to corresponding Objects in VB.NET.
<Control Name="LoginPage" LabelAlignment="Right" FieldAlignment="Left" DisplayPoweredByLogo="False">
<Fields>
<FieldGroup Name="Admin" Visible="True" LayoutPosition="Left">
<AdminID Visible="False" Required="False" EnableChange="False" Max...