Hi folks,
I need ur help, view the following code snippet

public xxxx func1()
{
--
--
return xx;
}

This is a sample function in C#. which may return string/Datetime/Datatable.

Is there any way by which same function return different data types at different times.
please reply asap.

You can write a generic function to return whatever type is required of a function. Here is a simple example.

public T GetDefaultValue<T>(T input)
{
    return default(T);
}

And using it

DateTime myDate = GetDefaultValue<DateTime>();
int myInt = GetDefaultValue<int>();
double myDouble = GetDefaultValue<double>();
string myString = GetDefaultValue<string>();
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.