|
Hi,
I'm a C++ programmer looking to learn C#, I have no experience with .NET, I bought "Essential C# 2.0" a few years back but never got a chance to read it.
Could somebody recommend a good C# book, preferably using the .NET 3.5 framework - these three all seem to be well rated so I don't know which (if any) to choose:
Apress - Pro C# 2008 and the .NET 3.5 Platform, Fourth Edition
Wrox - Professional C# 2008
C# 3.0 in a Nutshell: A Desktop Quick Reference
Thanks in advance for any suggestions.
|
|
|
|
|
321Markus123 wrote: Wrox - Professional C# 2008
-- I have an older version (from 2003) that I had to buy for a class way back then, it seems pretty good.
|
|
|
|
|
Hello people,
Is it posible to declare the type of a generic at runtime?
I mean, you normaly would have to do something like this:
GenericMethod<Type>();
And I want to do something like this:
GenericMethod<(expression that evaluates to a type)>();
I have tried a few things but nothing seems to work.
MSDN's C# Programming Guide states that:
"client code must declare and instantiate a constructed type by specifying a type argument inside the angle brackets. The type argument for this particular class can be any type recognized by the compiler."
Thanks!
|
|
|
|
|
You could always use a Func here. For instance:
GenericMethod<Func<T, TResult>>();
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
Thanks Pete,
And what exactly would this Func be or do?
Thanks again!
|
|
|
|
|
This[^] article should help. This type of functionality is the mojo behind Linq.
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
Good link Pete, very concise.
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn) Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia) Why are you using VB6? Do you hate yourself? (Christian Graus)
|
|
|
|
|
Thanks Pete, I read your link and it seems this particular feature it's not for C# 2.0, which is preciselly the version i'm working 
|
|
|
|
|
What kind of expression that evaluates to a type would you have there? Something with reflection? You could probably use reflection to invoke the method with an expression of the type Type , but I'm not actually sure. Reflection can do a lot though, so why not..
edit: If all else fails, there is still the possibility to compile and run a piece of code that has been generated at runtime. But I wouldn't use that except in emergencies. It's not exactly fast, or a clean design.
|
|
|
|
|
A method which may prove useful is Type.MakeGenericType[^]. I don't fully understand it, but it seems to be a step in the right direction - getting the type of a generic type (without the type specifiers), then calling MakeGenericType on the result to get a dynamically set Type
Between the idea
And the reality
Between the motion
And the act
Falls the Shadow
|
|
|
|
|
Man thanks a lot, it did worked:
Type cons = typeof(List<>).MakeGenericType(Tipo);
object _list = cons.Assembly.CreateInstance(cons.FullName);
+1 for you!
|
|
|
|
|
This code creates a generic type and instatiate an object of that type in runtime using MakeGenericType as Computafreak mentioned. I was going to post it last night but I forgot and fell asleep. But now I know you want it in .net 2.0 I have to remove var and new[]
static void Main(string[] args)
{
Type t = typeof(List<> );
Type gt = t.MakeGenericType(GetTypes());
object gtObj = Activator.CreateInstance(gt);
}
private static Type[] GetTypes()
{
return new Type[] { typeof(int) };
}
But gtObj is returned as an object (but it is a List<int>). The problem is that you will probably have to use reflection.
Eslam Afifi
|
|
|
|
|
|
You're welcome. I read your other post[^] and you don't have to use the FullName of the Type, you can just pass the Type directly which is faster IMHO.
Eslam Afifi
|
|
|
|
|
Yes indeed! I have corrected my code to use the Activator.
Thanks again!
|
|
|
|
|
i am looking for a way to list all the share on a given computer and also list all groups on users who have access and what access they have
|
|
|
|
|
Here[^] you go. There is an article right here[^] at CP.
For the other part, I guess this[^] would help.
|
|
|
|
|
what i am really looking to do is check the total right a users has to a share do i have to find out all the groups they are in and get all the rights for each group and calulate it my self or is there and easier way?
|
|
|
|
|
Hi All,
I accedentailly deleted a Sql Table .Can you give me an Idea how to recover it?
Thanks
|
|
|
|
|
Wrong forum.
Restore the back up if you have taken it.
|
|
|
|
|
I am not good in Sql ? Can you please get me a little bit of hint?
|
|
|
|
|
All i have is a Database.dat file ? is it the one i have to pick up.
|
|
|
|
|
|
How can i restore a database from a *.dat file?
|
|
|
|
|
When you reply to yourself do you get an email saying you have sent yourself a message?
Life goes very fast. Tomorrow, today is already yesterday.
modified on Friday, September 25, 2009 5:14 AM
|
|
|
|