How to remove negative sign from LINQ output [closed] - c#

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 9 years ago.
i have following linq used in my application
var FinalSubExpired = subExpired.Where(e => (DateTime.Now - Convert.ToDateTime(e.AreasOfLawTillDate)).TotalDays <= 30 ).ToList();
which returns the total days with negative values, i need to remove that negative sign from that total days. how can i do that by modifying this linq?
Please help.

var FinalSubExpired = subExpired.Where(e => Math.Abs((DateTime.Now - Convert.ToDateTime(e.AreasOfLawTillDate)).TotalDays) <= 30).ToList();
that should do the trick

try and use Math.Abs inside your Linq query, as:
var FinalSubExpired = subExpired.Where(e => (Math.Abs(DateTime.Now - Convert.ToDateTime(e.AreasOfLawTillDate)).TotalDays) <= 30 ).ToList();

Related

Mid as target of an assignment [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 9 years ago.
I try just an old VB application in c# to convert, while I've encountered this line of code:
Mid(strData, intPosition + 1, intLenght) = strValue
How can it be translated into c#?
You would have to combine Remove and Insert, something like:
strData.Remove(intPosition, intLenght).Insert(intPosition, strValue);
The above assumes that the length of strValue was equal to intLenght. If strValue might be longer, then to replicate the Mid statement, we would need to do:
strData.Remove(intPosition, intLenght)
.Insert(intPosition, strValue.Substring(0, intLenght));

How can I debug this LINQ query [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 9 years ago.
How can I debug linq query? when query is too long
Debuggen is very limited with linq. See the link #JW shown in the comment.
But in you case you could split it up. It makes it's easier to see thats going on.
var tmpLst = panelInfo.AsEnumerable()
.Where(panelModel =>
panelModel.Field<string>(modelNumberColumnName) == solution.ModelNumber)
.Select(panelModel => panelModel.Field<int>(voltageListSupportedColumnName))
.Distinct()
.ToList();
foreach(var item in tmpLst)
{
voltagesSupported.AddRange(
ModelInfoController.VoltageInfos[(uint)item]
.Select(voltage => (int)voltage)
.ToList()
}

How to round up the number in c# [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
How can I round up values like this:
1.001 => 2
3.3 => 4
Means if the number has fractional part than i want the smallest integer number greater than the number ?
I used Math.Ceiling() but is not helping. How can i do this ?
Math.Ceiling will work. can you tell what its not working ? in term of any errors or returned result.
var returnVal=Math.Ceiling(yourValue);
Use Math.Ceiling() method.
Returns the smallest integer greater than or equal to the specified
number.
var i = Math.Ceiling(1.001);
var j = Math.Ceiling(3.3);
Console.WriteLine(i);
Console.WriteLine(j);
Output:
2
4
Math.Ceiling(value);
Should work.
double x;
x = Math.Ceiling(5.2) ;//Result; 6
x = Math.Ceiling(5.7) ;//Result; 6
x = Math.Ceiling(-5.2) ;//Result;-5
x = Math.Ceiling(-5.7) ;//Result;-5
This is a simple example. How can't you use it? Maybe you miss to assign a variable to
Math.Ceiling();

How can I merge this two bits of code [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
How can I turn these two bits of code into one?
comCtrList = (from i in genOutList
join f in genAccList
on i.Contract equals f.Contract
select i.Contract).ToList();
genOutList.RemoveAll(acc => comCtrList.Contains(acc.Contract));
Do you want something like this?
genOutList= (
from i in genOutList
where !genAccList.Any(x=>x.Contract==i.Contract)
select i
).ToList();
Or
genOutList.RemoveAll(x=>genAccList.Any(i=>i.Contract==x.Contract));

Can't use 'contains' in LINQ [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
string last = url.Substring(url.LastIndexOf('/') + 1);
var provisionedSiteRequestRep = provisioningRequestRepository.SelectFirst(new WhereSpecification<ProvisioningRequest>(result => result.SiteUrl.Contains(last.ToString())));
Some time i am getting the null values of last.tosting() so i am getting exception for this code how to resolve this?
You are facing problem on this line
(result => result.SiteUrl.Contains(last.ToString());
Can you please check that SiteUrl is type of string otherwise it not going to work for you.
because last is type of string and Contains is method supported by string type ...
or
otherwise last need to be enumebrable collection and siteurl also enumerable collection than and only than Contains is supported

Categories

Resources