Click here to Skip to main content
15,913,939 members
Home / Discussions / C#
   

C#

 
QuestionCallbackOnCollectedDelegate exception when using DDE to get URLs from Navigators Pin
moums8-Jun-11 13:54
moums8-Jun-11 13:54 
Questionstring formate Pin
jashimu8-Jun-11 8:20
jashimu8-Jun-11 8:20 
AnswerRe: string formate Pin
Ennis Ray Lynch, Jr.8-Jun-11 8:29
Ennis Ray Lynch, Jr.8-Jun-11 8:29 
AnswerRe: string formate Pin
mabrahao8-Jun-11 9:07
mabrahao8-Jun-11 9:07 
AnswerRe: string formate Pin
AspDotNetDev8-Jun-11 9:16
protectorAspDotNetDev8-Jun-11 9:16 
AnswerRe: string formate Pin
AspDotNetDev8-Jun-11 9:15
protectorAspDotNetDev8-Jun-11 9:15 
GeneralRe: string formate Pin
jashimu8-Jun-11 11:04
jashimu8-Jun-11 11:04 
AnswerRe: string formate Pin
Pete O'Hanlon8-Jun-11 10:55
mvePete O'Hanlon8-Jun-11 10:55 
GeneralRe: string formate Pin
AspDotNetDev8-Jun-11 11:38
protectorAspDotNetDev8-Jun-11 11:38 
AnswerRe: string formate PinPopular
Luc Pattyn8-Jun-11 12:32
sitebuilderLuc Pattyn8-Jun-11 12:32 
GeneralRe: string formate Pin
AmbiguousName8-Jun-11 21:46
AmbiguousName8-Jun-11 21:46 
GeneralRe: string formate Pin
Lutosław11-Jun-11 12:13
Lutosław11-Jun-11 12:13 
AnswerRe: string formate Pin
Luc Pattyn11-Jun-11 12:17
sitebuilderLuc Pattyn11-Jun-11 12:17 
GeneralRe: string formate Pin
Lutosław11-Jun-11 12:45
Lutosław11-Jun-11 12:45 
AnswerRe: string formate Pin
Luc Pattyn11-Jun-11 12:51
sitebuilderLuc Pattyn11-Jun-11 12:51 
Questioninstantiating a generic object [modified] Pin
mabrahao8-Jun-11 5:53
mabrahao8-Jun-11 5:53 
Hi guys, i have a method like this: public List<t> listObj<t>() {}
and i want to instantiate a object with this type T, i tried this: T obj = new T(); doesnt work, so i tried T obj = default(T); and doesnt work too... how can i instantiete this obj??? Thanks.

The code:

public class MysqlDireto
{
private static MysqlDireto _instancia;
private static string connectionstring = "Server=;Database=;Uid=;Pwd=;";

public static MysqlDireto Instancia
{
get { return _instancia ?? (_instancia = new MysqlDireto()); }
}
public List<T> ObterLista<T>()
{
MySqlConnection conn = new MySqlConnection(connectionstring);
string comando = "SELECT * FROM " + typeof(T).Name;
MySqlCommand cmd = new MySqlCommand(comando, conn);
conn.Open();
MySqlDataReader leitor = cmd.ExecuteReader();
List<T> lista = new List<T>();

if (leitor.HasRows)
{
while (leitor.Read())
{
T obj = Foo<T>();
obj.GetType().GetProperty("Id").SetValue(obj, leitor["Id"], null);
lista.Add(obj);
}
}
conn.Close();
return lista;
}
public T Foo<T>() where T : class, new()
{
return new T();
}
}

modified on Wednesday, June 8, 2011 2:11 PM

AnswerRe: instantiating a generic object Pin
Ennis Ray Lynch, Jr.8-Jun-11 6:11
Ennis Ray Lynch, Jr.8-Jun-11 6:11 
GeneralRe: instantiating a generic object Pin
mabrahao8-Jun-11 7:43
mabrahao8-Jun-11 7:43 
GeneralRe: instantiating a generic object Pin
dasblinkenlight8-Jun-11 8:15
dasblinkenlight8-Jun-11 8:15 
GeneralRe: instantiating a generic object Pin
mabrahao8-Jun-11 8:36
mabrahao8-Jun-11 8:36 
GeneralRe: instantiating a generic object Pin
dasblinkenlight8-Jun-11 8:42
dasblinkenlight8-Jun-11 8:42 
GeneralFull example PinPopular
Ennis Ray Lynch, Jr.8-Jun-11 8:28
Ennis Ray Lynch, Jr.8-Jun-11 8:28 
GeneralRe: Full example Pin
mabrahao8-Jun-11 8:42
mabrahao8-Jun-11 8:42 
Questionitextsharp font question for pdf Pin
cromster8-Jun-11 3:42
cromster8-Jun-11 3:42 
AnswerRe: itextsharp font question for pdf Pin
BobJanova8-Jun-11 4:01
BobJanova8-Jun-11 4:01 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.