tags:

views:

57

answers:

2

I am getting a list of running processes via LINQ.

The two properties I want are "ProcessName" and "WorkingSet64".

However, in my UI, I want these properties to be called "ProcessName" and "ProcessId".

How can I remap the name "WorkingSet64" to "ProcessId"?

I did a pseudo syntax of what I am looking for below:

using System.Linq;
using System.Windows;
using System.Diagnostics;

namespace TestLinq22
{
    public partial class Window1 : Window
    {
        public Window1()
        {
            InitializeComponent();

            var theProcesses =
                from p in Process.GetProcesses()
                orderby p.WorkingSet64 descending
                select new { p.ProcessName, p.WorkingSet64 alias "ProcessId" };

            foreach (var item in theProcesses)
            {
                TheListBox.Items.Add(item);
            }
        }
    }
}
+5  A: 
select new { p.ProcessName, ProcessId = p.WorkingSet64 };
Mehrdad Afshari
damnit, you just beat me :(
Slace
+2  A: 
var theProcesses = from p in Process.GetProcesses()
                   orderby p.WorkingSet64 descending
                   select new { p.ProcessName, ProcessId = p.WorkingSet64 };

When you create an annonymous object if you provide the property name it'll use that, otherwise it'll use the name of the property you selected from.

Slace