473,498 Members | 1,998 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

return a private enum

Complete newbie at C#.

Class below stripped for brevity.
How do I return a private "Status" from a public method?
I may need a set/get but I don't know how to do that on an enum.

Thank you.
public class SomeClass
{
private enum Status {OK , NOK, UNK};

public Status check_status()
{
//...code to determine Status...
return NOK;
}
}

Jun 23 '06 #1
6 3666
return Status.NOK;

"Valmont" <ax***********@hotmail.com> schreef in bericht
news:44********************@dreader2.news.tiscali. nl...
| Complete newbie at C#.
|
| Class below stripped for brevity.
| How do I return a private "Status" from a public method?
| I may need a set/get but I don't know how to do that on an enum.
|
| Thank you.
|
|
| public class SomeClass
| {
| private enum Status {OK , NOK, UNK};
|
| public Status check_status()
| {
| //...code to determine Status...
| return NOK;
| }
| }
|
|
|
Jun 23 '06 #2
Valmont,

You can't. The type is declared as private, so you can't expose it.
You can return it as an int, and cast the return value, but you won't have
type safety.

Why not just make the enumeration public?
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Valmont" <ax***********@hotmail.com> wrote in message
news:44********************@dreader2.news.tiscali. nl...
Complete newbie at C#.

Class below stripped for brevity.
How do I return a private "Status" from a public method?
I may need a set/get but I don't know how to do that on an enum.

Thank you.
public class SomeClass
{
private enum Status {OK , NOK, UNK};

public Status check_status()
{
//...code to determine Status...
return NOK;
}
}

Jun 23 '06 #3
I don't think that will compile. The reason is that your return type
is of type Status, but you're not letting the outside world know how
Status is defined.

You'll have to make the enum public.

HTH
Andy

Valmont wrote:
Complete newbie at C#.

Class below stripped for brevity.
How do I return a private "Status" from a public method?
I may need a set/get but I don't know how to do that on an enum.

Thank you.
public class SomeClass
{
private enum Status {OK , NOK, UNK};

public Status check_status()
{
//...code to determine Status...
return NOK;
}
}


Jun 23 '06 #4
Solved.

Engineering error from my part. Blackout I suppose: enum stays private.

Thank you Nicholas and Andy for your very fast response though!

"Valmont" <ax***********@hotmail.com> schreef in bericht
news:44********************@dreader2.news.tiscali. nl...
| Complete newbie at C#.
|
| Class below stripped for brevity.
| How do I return a private "Status" from a public method?
| I may need a set/get but I don't know how to do that on an enum.
|
| Thank you.
|
|
| public class SomeClass
| {
| private enum Status {OK , NOK, UNK};
|
| public Status check_status()
| {
| //...code to determine Status...
| return NOK;
| }
| }
|
|
|
Jun 23 '06 #5
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote in
message news:%2****************@TK2MSFTNGP04.phx.gbl...

You can't. The type is declared as private, so you can't expose it.
You can return it as an int, and cast the return value, but you won't have
type safety.


What would you cast it to? :)

///ark
Jun 23 '06 #6
It doesn't make sense to return a private type from a public function.

How do you expose this class ?

public myenum func ()
implies that myenum is known to the calling code.

Otherwiae, you can only have
public int myfunc ()

or in your particular example you could have
public DialogResult func ()
which has values Yes, No, None etc

Valmont wrote:
Complete newbie at C#.

Class below stripped for brevity.
How do I return a private "Status" from a public method?
I may need a set/get but I don't know how to do that on an enum.

Thank you.
public class SomeClass
{
private enum Status {OK , NOK, UNK};

public Status check_status()
{
//...code to determine Status...
return NOK;
}
}

Jun 24 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
1919
by: mcdonamw | last post by:
This may sound like a stupid stupid question and I figure it would b more "general" than pertaining to a specific Language. I'm using vb.net and I have a bunch of Const values in my program. can...
4
1290
by: thechaosengine | last post by:
Hi all, I have a property called GeneralStatus that can return an int between -1 and 3. These values are represented by an enumeration called StatusEnum. My question is, should my property...
3
13883
by: Sanjay Pais | last post by:
I know that string/char enum is not possible in c# (.NET2.0) I need to create the equivalent of this: public enum HOW_GOOD { AWESOME = "A", GREAT= "G", NOT_TOO_BAD = "N", TERRIBLE="T" }
2
1808
by: tzvika.visman | last post by:
I write a MC++ wrapper for our company internal SDK that wrote in C++ native code for writing application with this SDK over C# and other .NET languages and most of my SDK API function return a...
6
4811
by: Bob | last post by:
It should be simple, but I'm stuck on this one... how do you return a value for an enum property type? TIA, Bob
5
1336
by: Tim Gallivan | last post by:
I have 2 functions, CheckThis and CheckThat. Each function can return some of the error codes in the Enum below (CheckThis can return 0, 1, 2 or 3 and CheckThat can return 0, 4, 5 or 6). I'm trying...
2
1149
by: Just Me | last post by:
I want to show a form Modally and return a value. Checking the documentation it looks like I need to return one of the DialogResults. Is that true or can I return any value? Thinking I...
1
2111
by: Fredrik Strandberg | last post by:
Hi! I would highly appreciate some help with how to access an enumeration declared as private in a class from the outside of the class. This is a simplified example of the situation: Const...
6
4365
by: bw171 | last post by:
I got some java code below, and upon trying to compile it in my unix environment, i get the following error ()> javac Downloader.java Downloader.java:37: ';' expected private enum...
0
6993
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7197
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6881
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7375
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
4584
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3088
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1411
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
650
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
287
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.