Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 7 years ago.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Improve this question
I use a Dictionary<string, Test> to store some datas, where the key is a file path. To display this dictionary I create a treeview with node names being the key of the corresponding test.
When I try to get back one value, I use:
Test test = Tests[node.Name];
But I throw me that:
The given key was not present in the dictionary.
So I made a few manual debug:
Console.WriteLine(node.Name + Environment.NewLine + Tests.First().Key);
Which outputs:
P:\poolman\LY21\2015\LY21_2015-03-25_03.xml <- The node name
P:\poolman\LY21\2015\LY21_2015-03-25_03.xml <- The dictionary first key
But keep crashing. How can I get rid of this?
I've added
Console.WriteLine(node.Name.Length + " " + Tests.First().Key.Length);
Which output
43 43
So it's not about the length.
In the Immediate window I tried this:
node.Name == Tests.First().Key
true
I really don't understand.
And one more lovely edit:
Tests.ContainsKey(node.Name)
true
Related
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 1 year ago.
Improve this question
An public string ItemSubType which is assigned a string "primary" by another script is somehow not equal to the string "primary". I've checked for empty characters but there isn't any. I've been absolutly stumped by this but also interested in how this is happening.
Debug.Log("---primary---");
Debug.Log("---" + ItemSubType + "---");
if(ItemSubType != "primary")
{
Debug.Log("This is ridiculous!");
}
Here is logs:A picture of the log
Thank you all for the comments!
After browsing through some other questions, I found .Trim().
Mystically there seems to be an invisible character in the string that isn't a whitespace character, as would be evident by the lack of spaces when adding '---' to either side.
By doing this:
ItemSubType = ItemSubType.Trim();
It fixed the Issue. To give some context, I pulled the string data from a csv file. I checked the file for any extra spaces but there wasn't any. Not sure if this is related tho.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 4 years ago.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Improve this question
I am attempting to define a queue named movingAverages with a size of queue.Count - period. I am getting an error "int IEnumerable.Count() ... - cannot be applied to method and int....
private static IEnumerable<DateClose> MovingAverage(
IEnumerable<DateClose> queue, int period)
{
Queue<DateClose> movingAverages = new Queue<DateClose>(queue.Count + period);
return movingAverages;
}
Well it's because IEnumerable<T>.Count is a method, so you are missing the parentheses at queue.Count + period, which should be queue.Count() + period.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 5 years ago.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Improve this question
I have a bit of a problem with my c# code.
I have a while loop:
while(current.parent != null)
{
solution.Add(current.move);
current = current.parent;
}
All of the variables have values, but for some reason it doesn't enter the while. I placed a break at the while and see that the parent property is not null, but it just skips the entire while.
Any ideas why? or how I can modify this to work?
Because current.parent is null to begin with.
Probably because current is the top most in your tree, i.e. has no children. (Or whatever you want to call it)
The code in your question is very vague but I would guess just using
solution.Add(current.move);
while(current.parent != null)
{
current = current.parent;
solution.Add(current.move);
}
may help.
This may solve the actual problem you are having (other than not knowing how to use a debugger ;))
So here you log the current move always, then log any parent moves.
Maybe look at refactoring this with a do..while loop!!
After seeing that every node in the tree had a null value (but the properties of the node weren't), I changed everything to work with the Node's properties instead, which finally worked.
Thanks guys =)
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 7 years ago.
Improve this question
Don't know what to title it, but here's what I have.
As you can see I have following lines of code where 1st and 2nd lines are okay but third line is causing error.
Can someone explain why? I have a feeling that it might be because (s is PaymentSchdule) needs to be evaluated at runtime, is that the reason?
Your syntax is incorrect. To check if something is of a specified type:
s is PaymentSchedule
Not
s is PaymentSchedule()
Resulting in you changing you code to:
Console.WriteLine("PaymentSchedule: " + (s is PaymentSchedule).ToString() + "Code: " + s.GetHashCode());
I'd be tempted to write it like this for better readability, though:
Console.WriteLine("PaymentSchedule: {0} Code: {1}", s is PaymentSchedule, s.GetHashCode());
You have written PaymentSchedule(). It should be PaymentSchedule
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
I'm using LINQ to read in some XML and then use that to set properties in an object. The XML looks like this:
<display_location>
<full>London, United Kingdom</full>
<city>London</city>
<state/>
<state_name>United Kingdom</state_name>
<country>UK</country>
<country_iso3166>GB</country_iso3166>
<zip>00000</zip>
<magic>553</magic>
<wmo>03772</wmo>
<latitude>51.47999954</latitude>
<longitude>-0.44999999</longitude>
<elevation>24.00000000</elevation>
</display_location>
And the code I have is:
select new Forecast
{
//Set properties for the display location
DisplayLatitude = (double)i.Element("display_location").Element("latitude"),
DisplayLongtitude = (double)i.Element("display_location").Element("longtitude"),
DisplayElevation = (string)i.Element("display_location").Element("elevation"),
};
I can correctly set the latitude and elevation however I'm getting the exception "Value cannot be null" when I try to parse the longtitude.
I think it might be because of the negative symbol. How do I fix this?
It's "longitude", not "longtitude". Your string needs to exactly match the XML element name or you'll get a null value instead.