TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Carl
NA
11
0
Generics and assigning variables
Jun 14 2007 2:03 PM
I try to define a generic function in c# that is capable of manipulating an array of integers, or an array of bools, depending on the parameter given to the function.
Is this possible?
E.g. I have the following code, this will result in a compile error.
void
fill_array<T>(
int
count,
ref
T[] array_out)
{
for
(int i= 0; ii < count; count++) {
if
(
typeof
(T) ==
typeof
(
int
)) array_out[i] = i % 2;
else
array_out[i] = (i % 2) == 1;
// results in cannot cast int to T, and cannot cast bool to T.
}
return
;
}
Reply
Answers (
1
)
Problem while writing to Remote Location in a .Net Thread
sorting array of objects