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
My question is part of this problem:
I recieve a collection of id's from a form. I need to get the keys, convert them to string and pass it to the db.
using (var db = new DbAmsecEntities())
{
cashsafelist = (from safe in db.Cashsafes
where safe.StoreId == (decimal)Convert.ToInt64(ddlLocationLists.SelectedValue)
select safe.CashsafeId).ToList();
cashsafevalues = cashsafelist.Select(x => x.ToString).ToList();//getting error here
}
You need to use () in ToString
cashsafevalues = cashsafelist.Select(x => x.ToString()).ToList();
You can also use List.ConvertAll which was available since 2.0.
cashsafevalues = cashsafelist.ConvertAll<string>(d => d.ToString());
It can be more efficient than ToList because the list will be initialized with the correct size.
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 5 months ago.
Improve this question
this for loop inside arrays is working like while and printing only the second index.
what should i do to make it print only even indexes?
You have inverted the += operator in your for loop. You're saying i = +2 which is the same as i = 2
The correct code would be:
for (int i = 0; i < cars.Length; i += 2)
{
Console.WriteLine(cars[i]);
}
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 months ago.
Improve this question
I have this linq query in my controller and it is working fine,
var Engineers = dbcontext.Employees.Where(i => i.Department == "Engineers");
but I would like to add a second condition to the query to filter out the results,
var Engineers = dbcontext.Employees.Where(i => i.Department == "Engineers" && i.UserStatus = 1);
Thanks for your help.
You made a typo, just need to use comparison operator (==) instead of assignation (=)
So it would be like that:
var Engineers = dbcontext.Employees.Where(i => i.Department == "Engineers" && i.UserStatus == 1);
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 4 years ago.
Improve this question
I am trying to check to see if this object contains any letters besides Z and if it does it should return Null. The way I have it initialized gives me no errors but when testing it does not actually return null if a letter is present.
if(request.DoorTag.Contains(#"[a - yA - Y]"))
{
return null;
}
if(Regex.IsMatch(request.DoorTag, "[a-yA-Y]")
{
return null;
}
But "[^zZ]" would even be better, since it'll check that your DoorTag contains any other char than Z
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);