|
Oh, so by top, you actually mean bottom?
Perhaps something like:
int[] values = list.Values.ToArray();
values.Sort();
int tr = values[values.Length - 10];
List<KeyValuePair<string,int>> = list.Where(item=>item.Value>=tr).ToList();
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
Thanks Guffa,
I am sorting a Dictonary< , > but you are sorting a List<>? I am confused about your code? For your code list.Values.ToArray(), where does the list variable comes from?
regards,
George
|
|
|
|
|
Sorry about the confusing name. The list variable is the dictionary...
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
Thanks Guffa!
I read your code again, but confused about the following statement.
1.
From left side of the assignment, do you miss a variable name?
2.
What does this operator mean <ptr>item=>item.Value>=tr?
List<KeyValuePair<string,int>> = list.Where(item=>item.Value>=tr).ToList();
regards,
George
|
|
|
|
|
George_George wrote: From left side of the assignment, do you miss a variable name?
Correct.
George_George wrote: What does this operator mean item=>item.Value>=tr?
It's a lambda expression. When it's not turned into an expression object it's equivalent to a delegate, which you can use if you don't have C# 3:
delegate(KeyValuePair<string,int> item){ return item.Value >= tr; }
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
Thanks Guffa,
I read and studied again about your pseudo code, I think it has good idea. But my current confusion is, there is no members called "where" as you used in your sample.
I am using C# 2.0, and can not use other version, like C# 3.
It is appreciated if you could re-write your sample code to make your ideas more clear?
regards,
George
|
|
|
|
|
Ok, then you have to do it the old fashoned way:
int[] values = dictionary.Values.ToArray();
values.Sort();
int tr = values[values.Length - 10];
List<KeyValuePair<string,int>> result = new List<KeyValuePair<string,int>>();
foreach (KeyValuePair<string,int> item in dictionary) {
if (item.Value >= tr) {
result.Add(item);
}
}
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
Thanks Guffa,
Smart!
regards,
George
|
|
|
|
|
Quickly, off the top of my head, you could create a linked list of objects with which you will do an insertion sort. You then run the dictionary, inserting objects into the array ONLY if the value is higher than the value at position zero OR if the array is empty. When inserting a new object, just insert it in the correct place.
Wow, I was being exceptionally thick tonight. I just realized that you could just use an OrderedDictionary.
Anyone who thinks he has a better idea of what's good for people than people do is a swine.
- P.J. O'Rourke
modified on Tuesday, July 22, 2008 2:56 AM
|
|
|
|
|
Thanks Joe,
This is what I am doing currently, I think this approach is manual and I want to find whether there are some existing classes/APIs could do this -- sort by value or key/value pair?
regards,
George
|
|
|
|
|
Hello All--
I have a List<double[]> Values, where each double[] is an array representing one series (not from a database). I can have several dozen double[] and each can be 100k+ items.
I would like to display this to the user in a datagrid (I know this is a lot of information, but the user needs to be able to browse). Due to the size, it is prohibative to load the entire thing into the grid at once, instead loading rows as needed. From Google, it seems like I need to bind this data source to the datagrid.
I've tried this:
currencyManager = (CurrencyManager)dataGridViewData.BindingContext[Data.Values];
dataGridViewData.DataSource = Data.Values;
But this displays the property of each List<> item (the double[]) in the grid (length, rank, etc).
Any suggestions on how to properly bind this data source?
Thanks
modified 12-Jul-20 21:01pm.
|
|
|
|
|
Hi all...
this is for an chat application....
i want to get system ideal time for setting the user status to ideal in the chat....
supposs if the system is ideal for 2 minut, I want to change the status of the logged in user to Ideal.
so can anyone help me to solve this problem....
Thanks in Advance
Vayanan
|
|
|
|
|
|
Hi Luc
Thank u very much
regards Vayanan
|
|
|
|
|
Hi,
Is there some macro recorder in c# like the VB macro recorder in MS Excel?
I have visual studio 2008 pro, i hoped it to be there when editing excel in visual c#.
Thanks
|
|
|
|
|
nelsonpaixao wrote: I have visual studio 2008 pro, i hoped it to be there when editing excel in visual c#.
I know there is one, not sure about the pro version, but I have that installed at work, so I can look for you in about 8 hours
|
|
|
|
|
Yes the Pro version does have a macro recorder.
|
|
|
|
|
I have a DataTable (dt) with a DataColumn (dc) whose Datatype is System.Int64.
I want this column to display the 64 bit Int in Hexadecimal format, as if the number had been converted like Int64Data.ToString("X") .
What property of a column controls this display? There's no "format" property for a column, and "Expression" appears to be for aggregation.
It's important that the column datatype remain INT64 (and not string), or I would just do the formatting conversion myself.
Can somebody point me to the correct method for setting the column display formatting?
Thanks.
|
|
|
|
|
Doh. Of course. You don't format the display of a DataTable DataColumn, because it's never displayed. You format the display of the column in the DataGridView, in which the DataTable data is displayed.
Man, you don't do any table stuff for a year, and you forget everything.
|
|
|
|
|
Hehe, it happens
|
|
|
|
|
Hi!
While browsing the .Net Framework source code I saw many methods marked extern , but without a DllImport attributte. My question is how could I use the extern keyword that way and when is it useful (no documentation on msdn; the only thing I found is this post[^].
For example, in String.cs:
[MethodImplAttribute(MethodImplOptions.InternalCall)]
private extern String PadHelper(int totalWidth, char paddingChar, bool isRightPadded);
And in comstring.cpp:
FCIMPL4(Object*, COMString::PadHelper, StringObject* thisRefUNSAFE,
INT32 totalWidth, CLR_CHAR paddingChar, CLR_BOOL isRightPadded)
{
CONTRACTL {
DISABLED(GC_TRIGGERS);
THROWS;
MODE_COOPERATIVE;
SO_TOLERANT;
} CONTRACTL_END;
STRINGREF refRetVal = NULL;
STRINGREF thisRef = (STRINGREF) thisRefUNSAFE;
HELPER_METHOD_FRAME_BEGIN_RET_ATTRIB_1(Frame::FRAME_ATTR_RETURNOBJ, thisRef);
WCHAR *thisChars, *padChars;
INT32 thisLength;
if (thisRef==NULL) {
COMPlusThrow(kNullReferenceException, L"NullReference_This");
}
(...)
So: how do I have to setup the compiler to build a program which has some methods marked as "InternalCall", without making a separate unmanaged DLL library.
Another question is why VS won't download the unmanaged parts of a source code and forces as to search for them manually...
Greetings - Gajatko
Portable.NET is part of DotGNU, a project to build a complete Free Software replacement for .NET - a system that truly belongs to the developers.
|
|
|
|
|
gajatko wrote: While browsing the .Net Framework source code I saw many methods marked extern, but without a DllImport attributte. My question is how could I use the extern keyword that way and when is it useful
This is normally built into the assembly. I do not know the exact details, but I think the method body just refers to some unmanaged section of code. I think you can 'get this' by using the Managed C++ compiler.
|
|
|
|
|
leppie wrote: I think you can 'get this' by using the Managed C++ compiler
How to compile a C# code with a Managed C++ compiler?
Greetings - Gajatko
Portable.NET is part of DotGNU, a project to build a complete Free Software replacement for .NET - a system that truly belongs to the developers.
|
|
|
|
|
Hi,
From a webservice, is it possible to print out something directy to the printer? (Without showing the default internet explorer print dialog). I need that because a few barcode printers required data in a special format (usually an ascii sequence)
Thanks,
Dirso
|
|
|
|
|
Dirso wrote: From a webservice, is it possible to print out something directy to the printer?
As long as your server has a printer it should work
|
|
|
|