Click here to Skip to main content
12,242,449 members (58,130 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as

Stats

3.6K views
Posted

Passing Enum type as a parameter

, 30 Aug 2011 CPOL
Rate this:
Please Sign up or sign in to vote.
"we cannot pass a Type as a function parameter" ???Yes we can. Just look at the parameter of Enum.GetValues for example._______Generic functions are unnecessary here. Just use Object.GetType to, um, get the type.private Enum GetNextEnum(object currentlySelectedEnum){ Type...
"we cannot pass a Type as a function parameter" ???

Yes we can. Just look at the parameter of Enum.GetValues for example.
_______

Generic functions are unnecessary here. Just use Object.GetType to, um, get the type.

private Enum GetNextEnum(object currentlySelectedEnum)
{
	Type enumList = currentlySelectedEnum.GetType();
_______

You could have used the generic type to return a value of the correct type.

private T GetNextEnum<t>(T currentlySelectedEnum)
{
	...
 
	return (T)enums.GetValue(index);
}</t>

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

jarvisa
Software Developer (Senior) Shaw Inspection Systems Ltd
United Kingdom United Kingdom
No Biography provided

You may also be interested in...

Comments and Discussions

 
-- There are no messages in this forum --
| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.160426.1 | Last Updated 30 Aug 2011
Article Copyright 2011 by jarvisa
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid