|
-
February 21st, 2009, 04:07 PM
#1
Parameterized type
A would be a C++ legitimate template doesn't work in C#:
public void PassDoubleArrayToList<T>( double [] x, List<T> items ) where T : struct
{
for( int i = 0; i < x.Count(); ++i )
{
items.Add( (T) x[i] );
}
}
The compiler complains: error CS0030: Cannot convert type 'double' to 'T'. Is there any work around? I would like to use only numeric types with T: double, int, bool, etc. I have tried a lot of ideas, so a piece of code would be appreciated greatly.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|