C
C#ā€¢2y ago
SWEETPONY

ā” How to correctly write this linq query?

I have following code:
private string FormatLocalDateLong(LocalDate localDate)
=> localDate
.ToString( "dd.MM.yyyy", _ruCulture );
private string FormatLocalDateLong(LocalDate localDate)
=> localDate
.ToString( "dd.MM.yyyy", _ruCulture );
I decided to extand function and did this:
private string FormatLocalDateLong( LocalDate localDate )
=> localDate
.ToString( "dd.MM.yyyy", _ruCulture )
.FormatResolvedValues();

public static string FormatResolvedValues( this string localDate )
=> localDate.EndsWith( "9999" )
? "/"
: localDate;
private string FormatLocalDateLong( LocalDate localDate )
=> localDate
.ToString( "dd.MM.yyyy", _ruCulture )
.FormatResolvedValues();

public static string FormatResolvedValues( this string localDate )
=> localDate.EndsWith( "9999" )
? "/"
: localDate;
All I want is to write the same without extansion FormatResolvedValues Smth like that but I don't understand how to write it correctly:
private string FormatLocalDateLong( LocalDate localDate )
=> localDate
.ToString( "dd.MM.yyyy", _ruCulture )
.EndsWith("9999")
? "/"
: ... (I don't want to write .ToString() again);
private string FormatLocalDateLong( LocalDate localDate )
=> localDate
.ToString( "dd.MM.yyyy", _ruCulture )
.EndsWith("9999")
? "/"
: ... (I don't want to write .ToString() again);
6 Replies
SWEETPONY
SWEETPONYā€¢2y ago
ah.. I don't know why.. but FormatLoclDateLong returns "/" or null ..
Tvde1
Tvde1ā€¢2y ago
private string FormatLocalDateLong( LocalDate localDate )
{
var stringDate = localDate.ToString( "dd.MM.yyyy", _ruCulture );
return stringDate.EndsWith("9999")
? "/"
: stringDate;
}
private string FormatLocalDateLong( LocalDate localDate )
{
var stringDate = localDate.ToString( "dd.MM.yyyy", _ruCulture );
return stringDate.EndsWith("9999")
? "/"
: stringDate;
}
šŸ™‚ or
private string FormatLocalDateLong( LocalDate localDate )
{
return localDate.Year == 9999
? "/"
: localDate.ToString( "dd.MM.yyyy", _ruCulture );
}
private string FormatLocalDateLong( LocalDate localDate )
{
return localDate.Year == 9999
? "/"
: localDate.ToString( "dd.MM.yyyy", _ruCulture );
}
SWEETPONY
SWEETPONYā€¢2y ago
I hadn't thought of that! thanks but any way I don't understand why my extension method returns null. it's strange
Tvde1
Tvde1ā€¢2y ago
that's weird indeed
SWEETPONY
SWEETPONYā€¢2y ago
ok my bad thanks for your idea
Accord
Accordā€¢2y ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.