Current area: HOME -> Blogs -> types

Blog Posts Tagged With types

When C# bites
Posted on Wednesday, November 28, 2007 at 6:25 AM
So I wanted to do:
private TTo Identity<TFrom,TTo>(TFrom I)
{
    return (TTo)I;
}
Well, actually I didn't. I wanted C# to be smart enough to realize that if S is a subtype of T then List<S> can safely be assumed to be a subtype of List<T>. But anyway, that's not the case, and you have to call ConvertAll on the List to get it to be a List<T> rather than a List<S>. Joy. Anyway, turns out the above fails to compile. Thankfully, this works:
private TTo Identity<TFrom,TTo>(TFrom I)
{
    return (TTo)(object)I;
}
But, argh.
Tags: C#, types

Learn C# 3.0 With Our New Series!
Posted on Wednesday, November 21, 2007 at 9:31 AM
This week we are starting a brand new four part series, covering the new features of C# 3.0! The first article of the series covers type inference. You'll learn:
  • What is type inference anyway?
  • How can you take advantage of it?
  • What does the new "var" keyword do?
  • Is this at all related to Variant types in Visual Basic?
  • Will using this hurt the performance of your programs at runtime?
Check out the article!
Tags: .NET, C#, C# 3.0, types

Subscribe

RSS Feed RSS Feed

More Tags

.NET C C# C# 3.0 C++ Embedded engineering service eveh3d firmware Hardware Linux Made-In-China offshore Operating System Outsource Perl product development Programming R&D Software

Help

Check out the Blog FAQ.




Newsletter | Submit Content | About | Advertising | Awards | Contact Us | Link to us |
© 1996-2008 Community Networks Ltd All rights reserved. Reproduction in whole or in part, in any form or medium without express written permission is prohibited. Violators of this policy may be subject to legal action. Please read Terms Of Use and Privacy Statement for more information. Development by Synchron Data - .NET development.