public IEnumerable <T> PickRandom<T>(IEnumerable<T> list, int number)
{
var random = new Random();
var total = list.Count();
var required = number;
foreach (var item in list)
{
if (random.Next(total) < required)
{
required--;
yield return item;
if (required == 0)
{
break;
}
}
total--;
}
}
How to select N Random Items from the List in C#
Calculate next due date based on start date frequency and current date in c#
Company has clients, each has different invoice start date and invoice frequency. I had to calculate and display next invoice date from current date + next month. i.e. invoice will always be raised in next month of service completion. e.g. Client A has invoice start date 01-Jan-2021 and invoice frequency is 5 months. Date when I am writing this post is 17-April-2021. So now next invoice date for Client A is 01-June-2021. For client B invoice start date is 01-March-2021 and invoice frequency is 3 months, then its next invoice date is 01-June-2021 and so on for all other client.
public class DateHelper
{
public static DateTime nextInvoiceDate(DateTime? InvoicingStartDate,
string invoicingFrequency)
{
int occurrence =
(DateTime.Now.Month - Convert.ToInt32(InvoicingStartDate?.Month))
/ Convert.ToInt32(invoicingFrequency);
int restInt =
(DateTime.Now.Month - Convert.ToInt32(InvoicingStartDate?.Month))
% Convert.ToInt32(invoicingFrequency);
DateTime next = InvoicingStartDate.Value;
int multi;
if (restInt == 0 && DateTime.Now < InvoicingStartDate)
{
if (Convert.ToInt32(invoicingFrequency) == 1 && occurrence < 0)
{
multi = 1;
}
else
{
multi = Convert.ToInt32(invoicingFrequency)
* Math.Abs(occurrence);
}
}
else
{
if (Convert.ToInt32(invoicingFrequency) == 1)
{
multi = Convert.ToInt32(invoicingFrequency)
* (Math.Abs(occurrence));
}
else
{
multi = Convert.ToInt32(invoicingFrequency)
* (Math.Abs(occurrence) + 1);
}
}
return next.AddMonths(multi);
}
}
- How to calculate a future date based on a given date ?
- Calculate next due date based on start date frequency and current date ?
- How to nearest future date from given date and frequency ?
- Best way to calculate next date from start plus frequency
- How to calculate next meeting date based on given frequency ?
The razortaghelper task failed unexpectedly
After updating Visual studio to New version, I suddenly started getting error
the razortaghelper task failed unexpectedly
Well after doing some research on Internet I came across following solutions
Added the following environment variable to my user environment to make it build again:
DOTNET_HOST_PATH%ProgramFiles%\dotnet\dotnet.exe
Simply go to Environment Variable, check following images
After clicking on Environment Variables, click on New, Pop up will open up, simply add entries as per following image and click Ok