Class StudentFeeCollection
{
public static bool CheckAdmissionMonth(int AdmissionNo)
{
}
public static DataTable CheckAdmissionMonth(int AdmissionNo)
{
}
}
Is this possible or not, please tell me.
Class StudentFeeCollection
{
public static bool CheckAdmissionMonth(int AdmissionNo)
{
}
public static DataTable CheckAdmissionMonth(int AdmissionNo)
{
}
}
Is this possible or not, please tell me.
You can use out parameter:
class StudentFeeCollection
{
public static void CheckAdmissionMonth(int AdmissionNo, out bool result)
{
........
}
public static void CheckAdmissionMonth(int AdmissionNo, out DataTable tbl)
{
.......
}
No, that's not possible. You need to make sure that the signature of each overload is unique.
From the documentation:
Changing the return type of a method does not make the method unique as stated
in the common language runtime specification. You cannot define overloads that
vary only by return type.
Reference: http://msdn.microsoft.com/en-us/library/vstudio/ms229029(v=vs.100).aspx
This is not possible. Imagine you're the compiler or the runtime--how would you know which return type the code was asking for? If you really need to support returning multiple datatypes from a method, using generics is your best bet. That said, looking at your specific example, I suggest not doing it here. Having one method that returns either a boolean or a DataTable
seems like a pretty shoddy design.
You can overload by argument types in c# but not by return type. As Arshad said you can use out/ref parameters since these are arguments and not return types.
Also you can't overload by generic constraints of arguments(say having 2 versions where one is a struct and another is a class). see https://msmvps.com/blogs/jon_skeet/archive/2010/10/28/overloading-and-generic-constraints.aspx
one reason to avoid return type overloading, from the c++ language description:
The reason is to keep resolution for an individual operator or function call context-independent.
note: in some programming language like haskell you can overload by return types see Function overloading by return type? for more info