|
Dictionary will not guarantee the order of contents. So an item inserted at the last won't be the last element of dictionary. So it doesn't make sense to get the last item.
Best wishes,
Navaneeth
|
|
|
|
|
Correct. The question is invalid.
|
|
|
|
|
Hi Jim,
I'm late to the party here, but certainly agree with the consensus that a dictionary by its nature ain't got no "last."
I'll have to try the "convert to Array" thing, though, out of curiousity to see what it does internally.
While you can definitely say a 'SortedDictionary has a "last" : that may not be at all what you are looking for here which I assume, is not "last" in the sense of "last in the sort order."
I can see two strategies :
1. switch to some kind of queue or stack where you know "who's on first" ... and last ? ... from the get go
2. define a class that inherits from Dictionary, and overrides the Add method and then keep an internal variable updated with the last key (or key/value pair) added.
Here's a quick idea for scenario 2 :
public class FirstLastDictionary<K, V> : Dictionary<K, V>
{
public K firstKeyAdded { get; set; }
public K lastKeyAdded { get; set; }
public void Add(K theKey, V theValue)
{
if(firstKeyAdded == null) firstKeyAdded = theKey;
lastKeyAdded = theKey;
base.Add(theKey, theValue);
}
}
and a quick and dirty test : assumes you have a button named 'button1 on a form that calls this event handler :
private void button1_Click(object sender, EventArgs e)
{
FirstLastDictionary<string, int> myFLdict = new FirstLastDictionary<string, int>();
Random r = new Random();
for (int i = 0; i < 100; i++)
{
int rndValue = r.Next();
myFLdict.Add("key " + rndValue.ToString(), rndValue);
Console.WriteLine("adding : " + rndValue);
}
Console.WriteLine("firstkeyadded = " + myFLdict.firstKeyAdded);
Console.WriteLine("firstkeyadded value = " + myFLdict[myFLdict.firstKeyAdded]);
Console.WriteLine("lastkeyadded = " + myFLdict.lastKeyAdded);
Console.WriteLine("lastkeyadded value = " + myFLdict[myFLdict.lastKeyAdded]);
}
best, Bill
"Many : not conversant with mathematical studies, imagine that because it [the Analytical Engine] is to give results in numerical notation, its processes must consequently be arithmetical, numerical, rather than algebraical and analytical. This is an error. The engine can arrange and combine numerical quantities as if they were letters or any other general symbols; and it fact it might bring out its results in algebraical notation, were provisions made accordingly." Ada, Countess Lovelace, 1844
modified on Tuesday, December 15, 2009 4:52 PM
|
|
|
|
|
OK I think I must be prejudiced coming from a C++/STL background where you do have associative arrays and iterators that can give a first and last elements. I always assumed this was standard, and figured .net would have the same thing.
|
|
|
|
|
Hey folks,
I'm trying to write a video (multimedia) application. What I want is two video objects running video clips. Once the first one stops, the other fades in and than back.
I want to render the video images on a surface, but I'm having problems converting the video image to a Texture.
I Have an IVMRWindowlessControl9 (called windowlessCtrl) which is (obviously) my Video Mixing Renderer. Using the GetCurrentImage function, I'll be able to get a pointer to the current video image in memory.
windowlessCtrl.GetCurrentImage(out currentImage);
Now I need to convert the currentImage pointer (IntPtr) to a texture in order to render the image. Can anybody help me?
Thanks!
|
|
|
|
|
1st Check that the currentImage is not null
currentImage != IntPtr.Zero
and then
BitmapInfoHeader bih = (BitmapInfoHeader)Marshal.PtrToStructure(currentImage , typeof(BitmapInfoHeader));
take care it depends of your pin, insure that your media type is a set to video and the output format is a video type.
|
|
|
|
|
|
Hi Everyone,
If anyone has even a remote idea of what might be wrong, please let me know so that we can test it.
We have written a Workflow service in C#, generated and then installed it. Problem is, it is not starting on the server. It starts up on my Dev machine fine, and on 2 other Dev pc's, but as soon as we install it to the server, I get the following error.
"error 1053:the service did not respond to the start or control request in a timely fashion"
I tried on my dev with the same service account used on the service, which didn't start until i added the account to the Administrator group. then it worked on my local dev. When adding the account to the server Admin group, still getting the same error...
Anyone know anything we can try to get this up and running? Are there specific framework installs we need to add perhaps for workflow services? I literally can't think of anything else to try.
Thanks,
Yoken
PS. My Dev machine runs : Win7, VS2008 | the server runs WinServ2003, all .net frameworks installed (1,2,3+)
|
|
|
|
|
|
thanks for the input Migounette,
unfortunately those links didn't help much. The patch is allready loaded yes, and the remote debug only works once the service has started... which is the problem I'm having.
I'll post any new developments related to this issue.
|
|
|
|
|
Hi All,
Just to let you know, after how long of searching for an answer, in the end the problem was inside the code on initializing a public variable.
instead of having [very rough]
public class myclass
{
workflowservicehost host = new workflowservicehost();
public myclass(...) {}
}
I had to change it to
public class myclass
{
workflowservicehost host;
public myclass(...)
{
host = new workflowservicehost();
}
}
Doing this fixed the "Error 1053", and the service started without hassle!
Now, if only I can find out WHY that worked on my dev machine (Win7, VS2008) and not when deployed to the server (WinServ2003), it sure would be great! My only thought is something to do with the underlying infrastructure, but any guess further that that is well.. yet another guess.
|
|
|
|
|
How can I distinguish between unary minus operator and binary minus operator in string format.
For example;
string formula = "3-4"; //Binary minus operator
string formula = "4+-1"; //Unary minus operator
string formula = "(-2)+1"; //Unary minus operator
Thanks...
|
|
|
|
|
A '-' is only binary when it follows a ')' or value, otherwise it's unary
|
|
|
|
|
when you parse an expression (scanning it left-to-right), you are looking for values and operators, and they normally alternate, starting with a value where operator means one of +-*/ and maybe more, and value means one of:
- numeric constant (digits; could also be hex, or real)
- identifier (=variable name)
- expression inside parenthesis
as a result a '-' is a binary minus whenever you are looking for an operator, and a unary minus whenever you are looking for a value.
furthermore you may check what follows the unary minus so you could reject these:
4+--2
4+-a
4+-(1+2)
|
|
|
|
|
I hate to correct you, but --2 is correct: -(-2) == 2, (as are the other two, now I think about it)! They may not be something you want to see, but they are valid and should work.
All those who believe in psycho kinesis, raise my hand.
|
|
|
|
|
in math --2 can be acceptable.
in compiler technology, especially with languages supporting ++ and -- operators, 4+--2 normally is rejected.
try again!
PS: that's why I said "may check" and "could reject"
modified on Tuesday, December 15, 2009 8:02 AM
|
|
|
|
|
Yes, just tried: the c# compiler sees --2 as trying to prefix decrement 2 and gives a "The operand of an increment or decrement operator must be a variable, property or indexer" error.
|
|
|
|
|
dataminers wrote: How can I distinguish between unary minus operator and binary minus operator in string format.
A string doesn't care - it doesn't know it is an operator at all!
If what you are asking is:
"How do I parse a string and decide whether a '-' character is a binary or unary operator" then the answer is: context.
An expression could be defined as
<operand><operator><operand> and an operand as:
<unary operator><operand>|<number>|...
All those who believe in psycho kinesis, raise my hand.
|
|
|
|
|
When I parse an expression into RPN[^];
When I find a plus or minus operator and
0) if I already have an operator in hand
or
1) if I have no operand in hand
the operator must be unary.
|
|
|
|
|
Hi all,
I have to create plugins toolbar(like google toolbar) for IE,FireFox and Flock
But I have no idea where to start for it.
I had search on google but not getting any help.
Thanks in advance.
|
|
|
|
|
I keep getting these errors when working with Directx (directsound) :
The call is ambiguous between the following methods or properties: 'Microsoft.DirectX.DirectSound.WaveFormat.WaveFormat()' and 'Microsoft.DirectX.DirectSound.WaveFormat.WaveFormat()'
The call is ambiguous between the following methods or properties: 'Microsoft.DirectX.DirectSound.BufferPositionNotify.BufferPositionNotify()' and 'Microsoft.DirectX.DirectSound.BufferPositionNotify.BufferPositionNotify()'
and so on...
Get it on xp, vista , visual 2005,2008 ...
Have no clue what is causing this errors, as everything compiles and works...
Learning without thought is labor lost; thought without learning is perilous. (Confucius)
|
|
|
|
|
Considering the classes are the same... aren't your project referencing two versions of the same DLL?
For example, when I changed the version of one of my dlls, projects referencing it where compiling, but the project was also referencing another DLL, that referenced an old version of the first dll, and so I get those errors at run-time.
Try checking all the references in your project. I am not sure, but that might be the cause.
* Also, try checking if you are not copying locally a DLL that is in the GAC. This can also end-up loading two versions of the same DLL, which in memory have different IDs and so, are ambiguous.
|
|
|
|
|
I have just one reference to the Microsoft.DirectX.DirectSound.dll, I set the copylocal to false.
If i compile the errors go away, but are there after a few seconds.
Where can I look for extra references ? In the project/solution file? app.config ?
Learning without thought is labor lost; thought without learning is perilous. (Confucius)
|
|
|
|
|
To be honest, I don't know. When I had this type of error the cause was the local copy or one of the DLLs I created also referencing the DLL, but at another version.
If you don't use DLLs created by you, I really don't know where to look.
But your project runs? Or you only get these messages as warnings? Maybe somehing the Visual Studio is referencing the dll again, but your project doesn't.
|
|
|
|
|
It will be something like that, but have no clue where these faulty references are.
It ain't warnings but real errors,and when I compile they disappear but are shortly after there again.
Anyway it's not a blocking factor but rather anoying.
Thanks for your time!
Learning without thought is labor lost; thought without learning is perilous. (Confucius)
|
|
|
|
|