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.
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
The testCards string picks up the value from web.config. But every time I try to use int.tryParse it gives a false value when I try to parse the string testCards. Any idea what I might be missing?
<add key ="TestCards" value ="4987654321098769,4111111111111111,4987654321098769"/>
string testCards = ConfigurationManager.AppSettings["TestCards"];
int flag=0
bool isSuceeded=false
isSuceeded = int.TryParse(testCards, out flag);
It's not an int! It has commas in it, and if it didn't have commas the number is much bigger than an int can hold in any .NET platform.
I'm gathering from the name TestCards that these are intended to be credit card numbers? In that case they should be strings.
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
When posting data from view, I send it to the Controller via ajax and split the date time value, then the parameter becomes a string and I want to convert it to my datetime, but I encounter such an error
There is a blank/space at the end of your 'date' string. Use bgdate.Trim(). You may also check that bgdate is a non null string and have then a default value with something like (bgdate == null)?"01-01-1970":bgdate.Trim().
There's a white space in your value 08-04-2021 . You should Trim() it:
bgdate.Trim()
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 2 years ago.
Improve this question
I have an oData api url where I am trying to replace querystring values with dynamic values.
I wish to pass comma separated string to one of my placeholder but I am getting error:
"Input string is not in correct format".
Here, in my "$select" placeholder I am passing comma separated string but it's failing with above error.
Here is my code:
string test = string.Format("https://myapiUrl/views/my_view_name?$filter=customer_id eq {} & $select={}", "101", "price,createdOn");
Can anybody guide me on this ?
Thanks !!!
string test = string.Format("https://myapiUrl/views/my_view_name?$filter=customer_id eq {0} & $select={1}", "101", "price,createdOn");
Have to add the number of the index of the parameter to the curly braces. (zero based)
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 3 years ago.
Improve this question
SML is a property of regelSML. I want to set regelSML to a value given by Reader.getString(i).
if(reader.GetName(i) = "SML") regelSML.SML = reader.GetString(i);
As clarification, like Guy wrote in the comments above, you are not doing a comparison in the condition.
A single = is for assignments.
You need the comparison-operator ==.
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 5 years ago.
Improve this question
I want to compare the month part of two values in linq but im getting an error
property or indexer DateTime.Month cannot be assigned to
Here's the code
var item = model.Where(d => d.DATE2.Date.Month = dto.StartDate.Month).FirstOrDefault();
model is a list of objects with datetime properties and the dto.Startdate is also a datetime
You may not come up with this question if you read the error message carefully, since its clear enough. Anyway, you have to use == here for comparing two values, = is for assignment purpose(basic knowledge). After making this small change your query will look like the following:
var item = model.Where(d => d.DATE2.Date.Month == dto.StartDate.Month).FirstOrDefault();
You can make them even simple by using FirstOrDefault instead for Where as like this:
var item = model.FirstOrDefault(d => d.DATE2.Date.Month == dto.StartDate.Month);