Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 2005 > C# 2005
|
C# 2005 For discussion of Visual C# 2005.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# 2005 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old November 29th, 2006, 07:32 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 217
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to mega
Default Generic return type

Hi all.
Does anyone know how I can define a method that can return both a DataTable and a int or string?
I've tried this:
Code:
internal interface IQuery
{
        void OpenConnection();
        void CloseConnection();
        T DoQuery<T>();
}
abstract internal class QueryClass : IQuery
{
...
    public abstract T DoQuery<T>();
}
class OpenQuery : QueryClass
{
     public override T DoQuery<T>()
     {
       DataTable dt = new DataTable();
            try
            {
                try
                {
                    this.OpenConnection();
                    dt.Load(Command.ExecuteReader());

                    return dt;
...
                }
            }
     }
}
...
OpenQuery query = new OpenQuery(queryname, parameters);
return query.DoQuery<DataTable>();
Obviously I can't return a DataTable when the return type is not defined in the DoQuery method and I can't call Load on a generic type. How do you guys work around this??

 - mega
Moving to C# .NET
__________________
- mega
Aspiring JavaScript Ninja
 
Old November 30th, 2006, 07:27 AM
Authorized User
 
Join Date: Sep 2006
Posts: 66
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi , If u return OBJECT .Its possible to return any type .






Similar Threads
Thread Thread Starter Forum Replies Last Post
Generic return type mega C# 4 November 30th, 2006 11:00 AM
return type? Sibananda Tripathy J2EE 1 January 3rd, 2005 04:03 AM
Generic Type specification during runtime ChronicCode General .NET 2 December 3rd, 2004 01:51 AM
Generic Type specification during runtime ChronicCode .NET Framework 2.0 0 December 2nd, 2004 12:55 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.