Results 1 to 2 of 2

Thread: Generic Method Reutn Type

  1. #1

    Thread Starter
    Fanatic Member Bombdrop's Avatar
    Join Date
    Apr 2001
    Location
    St Helens, England, UK
    Posts
    667

    Generic Method Reutn Type

    Can any one help I have a method that will return a List to be bound as a datasource to a combobox see code for population below. I get the following error when i try to compile
    Error 29 Cannot implicitly convert type 'System.Collections.Generic.List<Prsym.ComboPopulation.ComboInfo>' to 'System.Collections.Generic.List<T>
    '


    Code:
            /// <summary>
            /// Gets the data source to be bound to a ComboBox.
            /// </summary>
            /// <param name="storedProcedure">The Name of the Stored Procedure to be used.</param>
            /// <param name="scheme">The scheme.</param>
            /// <returns>A Generic List to be dound to a ComboBox</returns>
            private static List<T> GetDataSource<T>(string storedProcedure, PrsymScheme scheme)
            {
                Type dataSourceListType = typeof(T);
    
                if (dataSourceListType == typeof(ComboInfo)) {
                    List<ComboInfo> dataSourceList = new List<ComboInfo>();
                    ComboInfo datSourceComboInfo = new ComboInfo();
                    DataBaseAccess DBA = new DataBaseAccess(scheme);
                    SqlDataReader reader = null;
                    DBA.LoadData(ref reader, storedProcedure);
    
                    while (reader.Read()) {
                        datSourceComboInfo.Display = reader["Display"].ToString();
                        datSourceComboInfo.Index = Convert.ToInt32(reader["Index"].ToString());
                        dataSourceList.Add(datSourceComboInfo);
                    }
    
                    //Clean up
                    reader.Dispose();
    
                    System.Collections.ArrayList p = new System.Collections.ArrayList();
                  
                    return dataSourceList;
    
                } else {
                    return null;
                }              
    
            }
    Any help would be greatly received

  2. #2
    Hyperactive Member
    Join Date
    Dec 2006
    Location
    Ubuntu Haters Club
    Posts
    405

    Re: Generic Method Reutn Type

    By your original post title, I beleive the generic return method is object/Object, with the problem in your post, is there some sort of converter function from type 1 (System.Collections.Generic.List<Prsym.ComboPopulation.ComboInfo>) to type 2 (System.Collections.Generic.List<T>)?
    » Twitter: @rudi_visser : Website: www.rudiv.se «

    If Apple fixes security flaws, they are heralded as proactive. If Microsoft fixes a security flaw, they finally got around to fixing their buggy OS.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width