How can i implement a "optional" parameter to a function such that when endMarker
is not given, i will use the value from a required parameter startMarker
? i currently use a nullable type and check if endMarker
is null i set it to startMarker
protected void wrapText(string startMarker, string? endMarker = null) {
if (endMarker == null)
endMarker = startMarker;
}
but the problem now is i get an error saying it cannot cast string?
into string
(string)endMarker
how can i cast endMarker
to a string
so i can use it? or is there a better way of implementing this?