Click here to Skip to main content
15,900,532 members
Home / Discussions / C#
   

C#

 
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 
GeneralRe: itextsharp font question for pdf Pin
cromster8-Jun-11 4:28
cromster8-Jun-11 4:28 
GeneralRe: itextsharp font question for pdf Pin
BobJanova8-Jun-11 4:31
BobJanova8-Jun-11 4:31 
GeneralRe: itextsharp font question for pdf Pin
cromster8-Jun-11 4:39
cromster8-Jun-11 4:39 
AnswerRe: itextsharp font question for pdf Pin
Luc Pattyn8-Jun-11 5:22
sitebuilderLuc Pattyn8-Jun-11 5:22 
GeneralRe: itextsharp font question for pdf Pin
gavindon8-Jun-11 6:12
gavindon8-Jun-11 6:12 
QuestionAutoSizeMode = Cannot evaluate expression because a thread is stopped at a point where garbage collection is impossible, possibly because the code is optimized. [modified] Pin
Zadbuke8-Jun-11 0:53
Zadbuke8-Jun-11 0:53 
AnswerRe: AutoSizeMode = Cannot evaluate expression because a thread is stopped at a point where garbage collection is impossible, possibly because the code is optimized. Pin
Luc Pattyn8-Jun-11 1:48
sitebuilderLuc Pattyn8-Jun-11 1:48 
QuestionSending HttpWebRequest with a Unicode string Pin
ShadowUz7-Jun-11 18:58
ShadowUz7-Jun-11 18:58 

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.