Summation of data, linq [closed] - c#

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I want to summarize the "count" field where "Room" and "object code" are equal.
Any ideas?

I have no idea how is your context set, what is the table name and dozen other things that are necessary to answer your question, but it will definitely use GroupBy LINQ method, something like:
var results = db.TableName.GroupBy(x => new { x.Room, x.ObjectCode })
.Select(g => new { g.Key.Room, g.Key.ObjectCode, Count = g.Sum(x => x.Code) })
.ToList();

Related

Counting the amount of instances of a certain string in a list of objects, then formatting it in a certain way [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 8 years ago.
Improve this question
I have a list of objects which all contain a certain string. When I enumerate through them, I want to be able to identify all the matching ones and group them together, then format them all into a string like so: A005(x3), B006(x5), C002(x7),D001(x9).
Can anyone shed some light on a good way to do this?
This code should give you the desired result assuming you have a collection of strings.
strList.GroupBy(x => x)
.Select(x => string.Format("{0}(x{1})", x.Key, x.Count()));
Here is a test program:
var values = new[] {"A005", "B006", "C002", "D001",
"B006", "A005", "D001", "C002", "A005" };
var uniqueValues = values
.GroupBy(x => x)
.Select(x => string.Format("{0}(x{1})", x.Key, x.Count()));
Console.WriteLine(string.Join(", ", uniqueValues));
Produces this output:
A005(x3), B006(x2), C002(x2), D001(x2)

How to display a string variable in a specific number format like "#,0.##" [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I have a typed dataset with a column called price, which is of string datatype. And I'm showing this via ultrgrid/datagrid
How can I show the price in number format.
For example: price ==123456
in the grid it should be like 12,354,56
Try this
var a = price.ToString("##,###,##");
Reference
Custom Numeric Format Strings!
Look at some of the related links to the right of the screen. Some of them even ask the same question as you !

ArrayList<Uri> Intent. How to write in C# [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
How to write this in C#?
Intent intent = new Intent(Intent.ActionSendMultiple, Android.Provider.MediaStore.Images.Media.ExternalContentUri);
handler(intent);
....
void handler(Intent intent)
{
ArrayList<Uri> imageUris = intent.GetParcelableArrayListExtra(Intent.ExtraStream);
...
}
ArrayList is available is c# but it does not have a generic (<T>) form. ArrayList is a list of objects.
What you want is System.Collections.Generic.List<T>
EDIT : In response to comments, try this;
List<Uri> imageUris = new List<Uri>(intent.GetIntegerArrayListExtra(Intent.ExtraStream));
Easy, just use List<Uri>. It's also faster than ArrayList.

Remove items from one list in another c# with high performance [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I need remove all items step by step from list and add removed items to another list, but I need max effective and hithperformance operation. What is whe best practics?
You could use this code and hope that framework'll do the best for you:
public static void MoveItems<T>(List<T> list1, List<T> list2)
{
list2.AddRange(list1);
list1.Clear();
}
list2 = list1.ToList();
list1.Clear();

Linq query to get count like select 'iphone',count(*) [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 8 years ago.
Improve this question
SQL statement :
select 'iphone',count(*) from tablename where id=5
Result:
Name Num
'iphone' 50
How should i do with linq to get the same result(SQL statement)?
thanks in advance.
var Result = new { Name = "iPhone", Num = yourSequence.Count(x => x.Id == 5) };

Categories