Click here to Skip to main content
16,007,610 members
Home / Discussions / C#
   

C#

 
QuestionRe: treeview and tooltip Pin
Saamir6-Jun-07 4:34
Saamir6-Jun-07 4:34 
AnswerRe: treeview and tooltip Pin
Giorgi Dalakishvili6-Jun-07 4:31
mentorGiorgi Dalakishvili6-Jun-07 4:31 
QuestionRe: treeview and tooltip Pin
Saamir6-Jun-07 4:44
Saamir6-Jun-07 4:44 
GeneralRe: treeview and tooltip Pin
Saamir6-Jun-07 4:54
Saamir6-Jun-07 4:54 
GeneralRe: treeview and tooltip Pin
Giorgi Dalakishvili6-Jun-07 5:09
mentorGiorgi Dalakishvili6-Jun-07 5:09 
QuestionConnection with Oracle9i Pin
sarwarmdgolam6-Jun-07 4:16
sarwarmdgolam6-Jun-07 4:16 
AnswerRe: Connection with Oracle9i Pin
Tarakeshwar Reddy6-Jun-07 5:17
professionalTarakeshwar Reddy6-Jun-07 5:17 
QuestionUsing enumerated types Pin
Dewald6-Jun-07 3:56
Dewald6-Jun-07 3:56 
OK, this is probably the C++ programmer in me still trying to break through the C# fog (so far it's been quite a pleasant learning curve though).

I woud like to "give names" to the values that my functions return. In my C++ days I would have used something like

#define OK                0<br />
#define ERR_PORT_NOT_OPEN -100<br />
#define ERR_NO_CARRIER    -101

etc.

A function can then return ERR_PORT_NOT_OPEN if the port is not open as opposed to a meaningless int value of -100.

So I thought I'd go with enumerated types in C# and while it works I do feel that it could be a little more elegant.

I wrote a class called Defines with an enumerated type resembling this:
public enum ERR<br />
{<br />
   OK = 0,<br />
   PORT_NOT_OPEN = -100,<br />
   NO_CARRIER = -101,<br />
}


so now a function can return Defines.ERR.PORT_NOT_OPEN as opposed to -100.

My gripe with this approach is that I'm constantly having to typecast this enumerated type to (int). In other words the function has to return (int)Defines.ERR.PORT_NOT_OPEN and if I want to compare the outcome of a function with a switch for instance I have to do something like:
switch (myFunc())<br />
{<br />
   case (int)Defines.ERR.PORT_NOT_OPEN:<br />
      ...<br />
      break;<br />
   case (int)Defines.ERR.NO_CARRIER:<br />
      ...<br />
      break;<br />
}


I don't want to change the return type of the functions from int to Defines.ERR because I still have to use native functions which return int values (corresponding to the #define values of course).

So what do you guys do to achieve what I'm trying to?
AnswerRe: Using enumerated types Pin
DavidNohejl6-Jun-07 4:05
DavidNohejl6-Jun-07 4:05 
GeneralRe: Using enumerated types Pin
Dewald6-Jun-07 4:57
Dewald6-Jun-07 4:57 
AnswerRe: Using enumerated types Pin
Guffa6-Jun-07 4:10
Guffa6-Jun-07 4:10 
GeneralRe: Using enumerated types Pin
Dewald6-Jun-07 4:49
Dewald6-Jun-07 4:49 
GeneralRe: Using enumerated types Pin
Dave Kreskowiak6-Jun-07 5:06
mveDave Kreskowiak6-Jun-07 5:06 
GeneralRe: Using enumerated types Pin
Guffa6-Jun-07 9:05
Guffa6-Jun-07 9:05 
GeneralRe: Using enumerated types Pin
Dewald6-Jun-07 20:50
Dewald6-Jun-07 20:50 
GeneralRe: Using enumerated types Pin
Guffa6-Jun-07 8:59
Guffa6-Jun-07 8:59 
GeneralRe: Using enumerated types Pin
DavidNohejl6-Jun-07 21:23
DavidNohejl6-Jun-07 21:23 
Questionsending SMS Pin
faldupuja6-Jun-07 3:42
faldupuja6-Jun-07 3:42 
AnswerRe: sending SMS Pin
Dave Herren6-Jun-07 6:36
Dave Herren6-Jun-07 6:36 
QuestionFavourite Icon Pin
vibhas19826-Jun-07 2:49
vibhas19826-Jun-07 2:49 
AnswerRe: Favourite Icon Pin
I Believe In GOD6-Jun-07 2:57
I Believe In GOD6-Jun-07 2:57 
AnswerRe: Favourite Icon Pin
I Believe In GOD6-Jun-07 3:01
I Believe In GOD6-Jun-07 3:01 
AnswerRe: Favourite Icon Pin
Guffa6-Jun-07 3:59
Guffa6-Jun-07 3:59 
Questionupdating data Pin
sneha016-Jun-07 2:19
sneha016-Jun-07 2:19 
AnswerRe: updating data Pin
I Believe In GOD6-Jun-07 2:48
I Believe In GOD6-Jun-07 2:48 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.