Quantcast
Channel: Visual C# forum
Viewing all articles
Browse latest Browse all 31927

Overloading with identical parameters but different type results

$
0
0

The answer is probably no, but it can't hurt asking - is it possible to overload a method to accept same parameters, but return different type results? For example,

string[] x = TestMethod("fnord");

string x = TestMethod("fnord");

private static string[] TestMethod(string statement) { return new string[1]; } private static string TestMethod(string statement) { return string.empty; }

Naturally, I get an ambiguous statement error - while I know I can simply name the methods differently {i.e. ToArray, ToDataTable, ToDataReader, etc.}, I'm curious if there's a more elegant way to do it.

C# newbie, learning on the go. I will probably ask a lot of followup questions about any answers already given, so fair warning and all.


Viewing all articles
Browse latest Browse all 31927

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>