I have a program that prints dates(Fridays) between two dates, code work fine, but I am having some trouble, In Visual Studion it's not printing dayLeft but when I checked the same code at .net fiddle there it print dayLeft, Second thing I want to do how to use Skip() method for skipping the last two Fridays till 14/08/2021 Using the query, and how to add count-down from today to 14/08/2021, I mean days left from today to 14th of August, 2021. HOW TO DO IT IN SINGLE QUERY THAT PRINT DATES OR ALL FRIDAYS ALSO PERFORM DAYS LEFT CALCULATION
class Program { static void Main() { var dates = new List<DateTime>(); DateTime from = DateTime.Today; DateTime to = new DateTime(2021, 08, 14); double dayLeft = to.Subtract(DateTime.Today).TotalDays; //var to = DateTime.Today.AddDays(14); for (var dt = from; dt <= to; dt = dt.AddDays(1)) { dates.Add(dt); } var allFridays = dates.Where(x => (int)x.DayOfWeek == 5); Console.WriteLine(string.Join(Environment.NewLine, allFridays)); Console.WriteLine("Days Left are: ", dayLeft); Console.ReadKey(); } }
Console.WriteLine("Days Left are: {0} ", dayLeft);
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)