Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Strange compiling error on C# string.Join

Tags:

c#

In a uwp function, I am calling this:

var selectedDates = sender.SelectedDates.Select(p => p.Date.Month.ToString() + "/" + p.Date.Day.ToString()).ToArray();
var values = string.Join(", " + (string[])selectedDates);
CalendarViewResultTextBlock.Text = values;

But I got an error when compiling them:

Error CS0121 The call is ambiguous between the following methods or properties: 'string.Join(string, params object[])' and 'string.Join(string, params string[])'

Who knows how to fix it? Thanks.

like image 628
Ken Avatar asked May 31 '26 19:05

Ken


2 Answers

Try the following:

var values = string.Join(", ", (string[]) selectedDates );

(Remove the + sign)

like image 122
mayaht Avatar answered Jun 02 '26 09:06

mayaht


You have a wrong call. It should be

string.Join(", ", array) 

In your example it's + but should be **, **.

like image 20
Lukasz Szczygielek Avatar answered Jun 02 '26 08:06

Lukasz Szczygielek