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
haezeban
NA
6
0
Generics
Feb 12 2010 9:23 AM
Hi ,
Quite new to generics, I have a lot of methods with al the same code only the used classobject is different.But I do not know how to make this generic (it gives me errors) :
private
void
btn_Click(
object
sender,
EventArgs
e)
{
ArrayList
ar =
new
ArrayList
();
ar.Add(
""
);
this
.txtUitleg.Lines = (
string
[])ar.ToArray(
typeof
(
string
));
typeDataSource =
typeof
(
classname1
);
typeItems =
classname1
.Items.GetType();
codeTabel =
"
classname1
"
;
dataGridView2.DataSource =
classname1
.Items;
lblTitel.Text = codeTabel;
}
This is the code I have for about 10 different button_clicks events. Only the classname1 is different. So I think this is a good piece of code to use generics.
What I tried :
private
void
btn_Click(
object
sender,
EventArgs
e)
{
GenericsButton_Click();
}
private
void
GenericsButton_Click<T>(
)
{
ArrayList
ar =
new
ArrayList
();
ar.Add(
""
);
this
.txtUitleg.Lines = (
string
[])ar.ToArray(
typeof
(
string
));
typeDataSource =
typeof
(
T
);
typeItems =
T
.Items.GetType();
codeTabel =
T.ToString()
;
dataGridView2.DataSource =
T
.Items;
lblTitel.Text = codeTabel;
}
But this is not correct. Is it possible to point me out ?
Thanks
Reply
Answers (
4
)
AT commands and modems using serial port
vs 2008 c# make button visible