Note that there are some explanatory texts on larger screens.

plurals
  1. POReturning an array of culture formatted dates C# MVC3
    primarykey
    data
    text
    <p>I'm new to programming and trying to do an exercise that formats a date to the Thai culture in a variety of formats this is what I have for my code so far:</p> <pre><code> public String[] FormatAsSpecified(DateTime theDate, String theCulture, String[] formats) { String[] dateResults = new String[formats.Length]; CultureInfo culture = CultureInfo.GetCultureInfo(theCulture); for (int i = 0; i &lt; formats.Length; i++) { String culture_formatted_date = theDate.ToString(formats[i], culture); dateResults[i] = culture_formatted_date; } return dateResults; } </code></pre> <p>This is the test method that goes with it:</p> <pre><code> [TestMethod] public void FormatAsSpecifiedReturnsDateLiteralsInSpecifiedFormatForAllStandardFormatStrings() { //Arrange var controller = new DateController(); var theDate = new DateTime(2014, 2, 14, 9, 15, 32, 376); String theCulture = "th-TH"; // Array of all supported standard date and time format specifiers. String[] formats = { "d", "D", "f", "F", "g", "G", "m", "o", "r", "s", "t", "T", "u", "U", "Y" }; //Corresponding date literals for the standard Thai regional settings String[] expectedResults = {"14/2/2557" , "14 กุมภาพันธ์ 2557" , "14 กุมภาพันธ์ 2557 9:15" , "14 กุมภาพันธ์ 2557 9:15:32" , "14/2/2557 9:15" , "14/2/2557 9:15:32" , "14 กุมภาพันธ์" , "2014-02-14T09:15:32.3760000" , "Fri, 14 Feb 2014 09:15:32 GMT" , "2014-02-14T09:15:32" , "9:15" , "9:15:32" , "2014-02-14 09:15:32Z" , "วันศุกร์ที่ 14 กุมภาพันธ์ 2014 9:15:32" , "กุมภาพันธ์ 2557"}; //Act String[] actualResults = new String[15]; for (int i = 0; i &lt; formats.Length; i++) { actualResults[i] = controller.FormatAsSpecified(theDate, theCulture, formats[i]); } //Assert CollectionAssert.AreEqual(expectedResults, actualResults); } </code></pre> <p>I get an error in the test method at 'controller.FormatAsSpecified(theDate, theCulture, formats[i]);' that says "Argument 3, cannot convert from 'string' to 'string[]'" What am I doing wrong?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload