locked
Need help in creating an array and adding dates selected from the Calendar RRS feed

  • Question

  • User-1999980185 posted

    How would I add each dates in an array?  With the code below I get the first date the first time around then the second time I get the first and second date.  How do I get only the second date the second time and so on.   I would like the ShortDateString (only the date no time) Also how do I add these dates into a array.

    string[] ArrayNo = new string[31];

    foreach (DateTime d in Calendar1.SelectedDates)
    {
    s += d.ToShortDateString();

    }

    Saturday, October 13, 2018 12:13 AM

Answers

  • User-1999980185 posted

    Still need help with the code and message below:

    Code and Error Messages Below:
    
    foreach (DateTime d in Calendar1.SelectedDates)
                    {
                   
                    var ArraNo = Calendar1.SelectedDates.Select(d => ToShortDateString()).ToArrat();
    
                    if (Check_Date_Swch == "no")
                        Process_First_Date = Working_day;
    
                    Check_Date_Swch = "yes";
                    
                   // ArrayNo = ArrayNo + 1;
                }
    
    
    Error Message
    Severity	Code	Description	Project	File	Line	Suppression State
    Error	CS1061	'SelectedDatesCollection' does not contain a definition for 'Select' and no extension method 'Select' accepting a first argument of type 'SelectedDatesCollection' could be found (are you missing a using directive or an assembly reference?)	FirstCWeb	C:\Users\Edward\documents\visual studio 2015\Projects\MyFirstCWeb_Solution\FirstCWeb\calendarMonthly.aspx.cs	268	Active
    Severity	Code	Description	Project	File	Line	Suppression State
    Error	CS0136	A local or parameter named 'd' cannot be declared in this scope because that name is used in an enclosing local scope to define a local or parameter	FirstCWeb	C:\Users\Edward\documents\visual studio 2015\Projects\MyFirstCWeb_Solution\FirstCWeb\calendarMonthly.aspx.cs	268	Active
    

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, October 14, 2018 9:39 AM
  • User-1999980185 posted

    I went around the problem, but I never got the above code to work.  I have close the thread.   

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, October 14, 2018 3:04 PM

All replies

  • User303363814 posted

    var ArrayNo = Calendar1.SelectedDates.Select(d => d.ToShortDateString()).ToArrat();

    Sunday, October 14, 2018 6:40 AM
  • User-1999980185 posted

    Still need help with the code and message below:

    Code and Error Messages Below:
    
    foreach (DateTime d in Calendar1.SelectedDates)
                    {
                   
                    var ArraNo = Calendar1.SelectedDates.Select(d => ToShortDateString()).ToArrat();
    
                    if (Check_Date_Swch == "no")
                        Process_First_Date = Working_day;
    
                    Check_Date_Swch = "yes";
                    
                   // ArrayNo = ArrayNo + 1;
                }
    
    
    Error Message
    Severity	Code	Description	Project	File	Line	Suppression State
    Error	CS1061	'SelectedDatesCollection' does not contain a definition for 'Select' and no extension method 'Select' accepting a first argument of type 'SelectedDatesCollection' could be found (are you missing a using directive or an assembly reference?)	FirstCWeb	C:\Users\Edward\documents\visual studio 2015\Projects\MyFirstCWeb_Solution\FirstCWeb\calendarMonthly.aspx.cs	268	Active
    Severity	Code	Description	Project	File	Line	Suppression State
    Error	CS0136	A local or parameter named 'd' cannot be declared in this scope because that name is used in an enclosing local scope to define a local or parameter	FirstCWeb	C:\Users\Edward\documents\visual studio 2015\Projects\MyFirstCWeb_Solution\FirstCWeb\calendarMonthly.aspx.cs	268	Active
    

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, October 14, 2018 9:39 AM
  • User-1999980185 posted

    I went around the problem, but I never got the above code to work.  I have close the thread.   

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, October 14, 2018 3:04 PM
  • User1724605321 posted

    Hi db2tech ,

    How would I add each dates in an array?  With the code below I get the first date the first time around then the second time I get the first and second date.  How do I get only the second date the second time and so on

    "+=" will append the string . You can try to use below code sample  :

                List<string> list = new List<string>();
    
                foreach (DateTime d in Calendar1.SelectedDates)
                {
                    list.Add(d.ToShortDateString());
    
                }
    //add these dates into a array var arrray = list.ToArray();

    Best Regards,

    Nan Yu

    Monday, October 15, 2018 2:36 AM