Closed. This question needs debugging details. It is not currently accepting answers.
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.
Closed 4 years ago.
Improve this question
To manage rounding there are usually two methods, the first method is round values then to sum them. Or sum values then to round them. Of course to the required precision that you want.
I want to go with the first method and I need to update this line that currently do the opposite.
this.ClonedEntity.MontantHT = ArroundDecimal.CustomDecimalArround(correctedLines.Sum(l => l.MontantHT ?? 0));
When I try to call my static method in the lambda expression it doesn't work.
How would you suggest to do it while keeping use of the linq syntax ?
Thank you.
You could try something like this:
this.ClonedEntity.MontantHT = correctedLines
.Select(x=>ArroundDecimal.CustomDecimalArround(x.MontantHT ?? 0))
.Sum();
something = correctedLines.Sum(l => ArroundDecimal.CustomDecimalArround(l.MontantHT ?? 0))
Related
Closed. This question needs debugging details. It is not currently accepting answers.
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.
Closed 1 year ago.
Improve this question
So I made a simple c# file reader because I was bored and added an if statement to filter the results. But when I ran it, it gave me more results than I wanted. I was supposed to get
276, 2, and there was only one line inside the file with that value, but I got multiple. I checked the file and it had lines ending with the same value. I tried string.Equals(line, "276, 2") but it gave me the same results. I doubt there isn't something in c# that doesn't solve this issue.
You can use Regex, as it's mentioned in this issue
bool result = Regex.IsMatch(line, "\\b276, 2\\b");
Closed. This question needs debugging details. It is not currently accepting answers.
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.
Closed 6 years ago.
Improve this question
I have a table with 30 rows, i want to fetch rows from 15-25 using LINQ, tried using Range operator but that is not working in my scenario.
any help appreciated.
You can use <your linq>.Skip(n).Take(m), which will take the values between n and m.
You can use Skip() and Take() for that:
var result = query.Skip(14).Take(11);
(But I'm not 100% sure your query provider can translate that correctly to sql).
Closed. This question needs debugging details. It is not currently accepting answers.
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.
Closed 7 years ago.
Improve this question
I have the following regex pattern:
-?\d+(?:\.\d+)?%
Which works really well to match percentages. Now what I need is to be able to get the numerical value of this in a group.
I have tried the following:
(?<percentage>-?\d+(?:\.\d+)?)%
(?<percentage>-?\d+(\.\d+)?)%
(?<percentage>(-?\d+(?:\.\d+)?))%
(?<percentage>(-?\d+(\.\d+)?))%
None of them work and I only get the integer part of the percentile.
How can this be accomplished?
The correct regex is:
(?<percentage>-?(?:\d*\.?\d+|\d+\.?\d*))%
I tried the following examples and they all seemed to work (using the first regex that you tried):
Regex.Match("12%", #"(?<percentage>-?\d+(?:\.\d+)?)%").Groups["percentage"].Value
// 12
Regex.Match("12.345%", #"(?<percentage>-?\d+(?:\.\d+)?)%").Groups["percentage"].Value
// 12.345
Regex.Match("-12.345%", #"(?<percentage>-?\d+(?:\.\d+)?)%").Groups["percentage"].Value
// -12.345
You might note the use of the "#" in front of the regular expression string - maybe that is the issue you are having.
Closed. This question needs debugging details. It is not currently accepting answers.
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.
Closed 7 years ago.
Improve this question
How do I get a count of all items in a Mongo collection, using the 2.x C# driver?
I'm trying to use CountAsync, which I need to pass in a filter. I don't want to filter - I want everything returned.
You can always pass the empty document in the method like this
db.collection.CountDocumentsAsync(new BsonDocument());
db.collection.count()
In C# you can use Count() on the cursor of your collection.
Try as below:
var mongo = new Mongo();
mongo.Connect();
var db = mongo.GetDatabase("DatabaseName");
var collection = db.GetCollection<Product>();
var totalCount= collection.Count();
you can check in the following URL
this url
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I'm unable to determine why I don't get my expected output, given this code:
int periods = (location.Length / 2) - 1;
for (int index = 2, i = 0; i < periods; index += 3, ++i )
{
location = location.Insert(index, ".");
}
And a location of "C5032AC", I expect that location will equal "C.50.32.A.C" after my loop terminates; it is instead "C5.03.2AC". Can anyone explain what I'm missing here?
I would investigate using regular expressions to help you achieve this goal. You should be able to create a regular expression that matches specific patterns in the string, and you should be able to insert characters between those matches. Please see this article Regular Expressions MSDN
I've been asked to provide a bit of code to help support this. I don't believe regular expressions are overkill, and I believe something along the lines of this example will provide at least a step in the right direction.
line=Regex.Replace(line,#"([\w])(\d{2})(\d{2})(\w)(\w)","$1.$2.$3.$4.$5");