working with generics
create a class-->>declare the properties/variable-->>with in the class create a Method with inherited one(here it will be inherited from the Interface{Class:Interface})
public class sample:ICreatable
{
public string ramu {get;set;}
public void Create(SqlDataReader Reader)
{
ramu=Convert.ToString(Reader["DBname"]);
}
}
/*------this is the list-------*/
List<sample> sampledata = new List<sample>();
public class DAGetList
{
public static List<T> GetListFromCommand<T>(SqlCommand sqlcmd)
where T : ICreatable, new()
{
List<T> results = new List<T>();
using (sqlcmd.Connection)
{
sqlcmd.Connection.Open();
SqlDataReader sdr = sqlcmd.ExecuteReader();
while (sdr.Read())
{
T newthing = new T();
newthing.Create(sdr);
results.Add(newthing);
}
}
return results;
}
}
public interface ICreatable
{
void Create(SqlDataReader reader);
}
create a class-->>declare the properties/variable-->>with in the class create a Method with inherited one(here it will be inherited from the Interface{Class:Interface})
public class sample:ICreatable
{
public string ramu {get;set;}
public void Create(SqlDataReader Reader)
{
ramu=Convert.ToString(Reader["DBname"]);
}
}
/*------this is the list-------*/
List<sample> sampledata = new List<sample>();
public class DAGetList
{
public static List<T> GetListFromCommand<T>(SqlCommand sqlcmd)
where T : ICreatable, new()
{
List<T> results = new List<T>();
using (sqlcmd.Connection)
{
sqlcmd.Connection.Open();
SqlDataReader sdr = sqlcmd.ExecuteReader();
while (sdr.Read())
{
T newthing = new T();
newthing.Create(sdr);
results.Add(newthing);
}
}
return results;
}
}
public interface ICreatable
{
void Create(SqlDataReader reader);
}