473,326 Members | 2,133 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

Determine Type of Generic

I am trying to determine the Type of the call to a Generic method:
public static void Main()
{
Check<string>();

}
public static void Check<T>()
{
Type n = T.GetType();
Console.WriteLine(n.Name );
}

Is there a way to do this?

Jul 7 '07 #1
1 1835
Thanks Alberto! I was close on that!

So, what I was hoping to do is create a new type of that object and
use it
using System;
using System.Collections.Generic;

public class MyClass
{
public static void Main()
{
Check<MyItem>();
}
public static void Check<T>() where T:new()
{
Type n = typeof(T);
T obj = new n() ;
obj.Name="MyName";
Console.WriteLine(obj.Name);

}

}
class MyItem{
private string _name;
public string Name
{ get { return _name;}
set {_name = value; }
}
public MyItem(){ Console.WriteLine("Constr");}

}

Jul 7 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

17
by: John Bentley | last post by:
John Bentley: INTRO The phrase "decimal number" within a programming context is ambiguous. It could refer to the decimal datatype or the related but separate concept of a generic decimal number....
18
by: Christopher W. Douglas | last post by:
I am writing a VB.NET application in Visual Studio 2003. I have written a method that handles several events, such as closing a form and changing the visible status of a form. I have some code...
21
by: Walter L. Preuninger II | last post by:
I would like to write a generic procedure that will take string or numeric variables. I can not think of a way to make this more clear except to show what I want. int main(void) { int i=7;...
4
by: =?Utf-8?B?R3JlZw==?= | last post by:
I am a newbie to WCF so please forgive if this is an obvious question. I have the following. (Service contract) IEmployee public interface IEmployee { List<EmployeeGetEmployeeByID(string...
4
by: Weeble | last post by:
I have an interface that looks something like this: public interface IFoo<Twhere T : IFoo<T{ ... } Inside a class that looks something like this... public class Bar<V{ ... } ....I would like to...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.