Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I have two IEnumerable data collections that I would like to compare and get first collection values selected.
Here is what I am trying to do.
ClassA
Column|IsMatched
----
1
2
2
2
3
4
5
ClassB
Column
1
2
7
3
5
2
After comparison, I would like to get following.
ClassA
Column|IsMatched
1 true
2 true
2 true
2 false
3 true
6 false
5 true
4 false
Second collection may be in any order.
Any help to sort this issue would be really appreciated.
Thanks
You could do something like the following:
var workingBag = new List<int>(secondCollection);
var results = firstCollection.Select(i => new ClassA(i, workingBag.Remove(i));
Related
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 months ago.
Improve this question
I am working on a C# program where I need certain output numbers for formatting a printable string. This will help me in determining on how many /r/n I need to add between different datasets internally.
It is in WinForms.
public int GiveMeOutput(int input)
{
int output = 2;
//logic here
return output;
}
Can anyone help me in any language for the logic?
Greatly appreciate your help.
I would be getting the input into a Function(int input) & it should throw the "int" output.
Below is the table I want
If Input is
Then Output should be
5
2
6
2
7
3
8
3
9
4
10
4
11
5
12
5
13
6
14
6
...continues
...continues
This should do the trick:
int Map(int input)
{
return (input - 2 + input % 2) / 2;
}
Subtract 2, add 1 to odd numbers, then divide by 2.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
I basically want to go through the 2d List<> and deposit the sum of the items in a column to a 1d List. So far have a double for loop but I cant figure out the logic. Any help with how I can start to contruct it logically would be helpful. Thank you. This is the code I have so far:
So if you have this:
var grid = new List<List<int>> {
new() { 1,2 },
new() { 3,4 }
}
You can do:
grid.Pivot().Select(c => c.Sum());
And you'll get an enumerable that is { 4, 6 } (1+3 and 2+4)
You can get Pivot from fubo's answer here (or choose any one of the other suggested transforms)
If I misunderstood and you wanted {3,5} just skip the Pivot part
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
I tried to print every pair of element while it's factorial
language: language-c
#include<studio library>//
in main function I try to store 2D array which size is
a[1][3];
And, I write these code
integer a[1][3] = {1,2,3,4,5};
and I find factorial of 5 = 120
I have to print three element together
it is possible 120 times;
so ,I can try 120 different value using print function function
in a[1][3];
like this output
1,2,3 is 1.
1,2,4 is 2.
1,2,5 is 3.
1,3,4 is 4.
1,3,5 up to 120
I want to know that how to store value in 2D array
but the array is a[1][3]
You may set the values of j and k to be "i-dependent" but they are not updating their value, you should add a j++,k++ next to the i++
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
This is my table
ID SubID
============
1 1001
1 4432
1 2345
1 6322
2 2014
2 5432
The final result in treeview list should be
1
--1001
--4432
--2345
--6322
2
--2014
--5432
How to do that? Those data are stored in DataTable.
You can set the "key" of a node and check if it exists. If it doesn't, add it, then you can reference that key to add the child nodes:
foreach (DataRow dr in table.Rows) {
if (!treeView1.Nodes.ContainsKey(dr["ID"].ToString())) {
treeView1.Nodes.Add(dr["ID"].ToString(), dr["ID"].ToString());
}
treeView1.Nodes[dr["ID"].ToString()].Nodes.Add(dr["SubID"].ToString());
}
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
I have a list I want to remove the column RiskRegisterEntryId and RiskRegisterTypeId how can I to do that..?
SeriesNumber RiskRegisterEntryId RiskRegisterTypeId RiskRegisterType
RCMSRA19111300001 1 1 Site Risk Audit
RCMSRA19111300002 2 1 Site Risk Audit
RCMSRA19111300003 3 1 Site Risk Audit
RCMSRA19111300004 4 1 Site Risk Audit
RCMSRA20111300016 16 1 Site Risk Audit
You can just create a new list of an anonymous type without those columns:
var newList = myList.Select(l => new {
l.SeriesNumber , l.RiskRegisterType
}).ToList();
List.Select(x => new { x.SeriesNumber, x.RiskRegisterType});
This will create a list with an anonymous type containing only those two fields.