C# 获取当年的周六周日

 public void GetWMDay()
        {
            List<string> list = new List<string>();
            string year = "2019";
            DateTime counYear = Convert.ToDateTime(year + "-01-01"); //
            DateTime nestYear = counYear.AddYears(1);

            for (DateTime i = counYear; i < nestYear; i = i.AddDays(1))
            {
                if ((int)i.DayOfWeek == 0)
                {  // 周日    to do   }

                    list.Add("周日" + i.ToShortDateString());
                }
                else if ((int)i.DayOfWeek == 6)
                {   //周六  to do  }       
                    list.Add("周六" + i.ToShortDateString());
                }
            }

            MessageBox.Show("完成");
        }
  /// <summary>
        /// 获得指定年,月 的周六和周日的   年月日
        /// </summary>
        /// <param name="year"></param>
        /// <returns></returns>
        public List<DateTime> GetWMDay(int year,int month)
        {
            List<DateTime> list = new List<DateTime>();
            DateTime counYear = Convert.ToDateTime(string.Format("{0}-{1}-01",year,month)); 
            DateTime nestYear = counYear.AddMonths(1);
            for (DateTime i = counYear; i < nestYear; i = i.AddDays(1))
            {
                if ((int)i.DayOfWeek == 0)
                {  // 周日    to do   }

                    list.Add(i);
                }
                else if ((int)i.DayOfWeek == 6)
                {   //周六  to do  }       
                    list.Add(i);
                }
            }
            return list;
        }
原文地址:https://www.cnblogs.com/enych/p/10210405.html