473,402 Members | 2,064 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,402 software developers and data experts.

Return string + enum?

Hello

I was wondering if it's possible to return both a string and an enum value?
both "I have a caddilac" and CADDILAC? as an example..

if so, could you guys show me?

TIA
/Lasse
Nov 15 '05 #1
2 1493
"Lasse Edsvik" <la***@nospam.com> wrote in message
news:OG**************@TK2MSFTNGP12.phx.gbl...
Hello

I was wondering if it's possible to return both a string and an enum value? both "I have a caddilac" and CADDILAC? as an example..

Hi /Lasse,

Here is one way (pseudo code - I didn't compile this):

public string MyMethod(out MyEnumType myEnum)
{
// do method stuff
myEnum = MyEnumType.CADDILAC;
return "I have a caddilac";
}

Call it like this:

MyEnumType anEnum;

string myString = MyMethod(out anEnum);

Console.WriteLine("Enum: {0}, String: {1}", anEnum, myString);

Other possibilities include creating a struct with the enum and string type
and returning the struct, returning an enum from the method and making the
string an out parameter, or making both the enum and the string out
parameters.

Joe
--
http://www.csharp-station.com
Nov 15 '05 #2
Joe,

ok, thanks for helping :) i'll try it out later.

/Lasse
"Joe Mayo" <jm***@ddiieessppaammeerrssddiiee.com> wrote in message
news:eX**************@TK2MSFTNGP10.phx.gbl...
"Lasse Edsvik" <la***@nospam.com> wrote in message
news:OG**************@TK2MSFTNGP12.phx.gbl...
Hello

I was wondering if it's possible to return both a string and an enum value?
both "I have a caddilac" and CADDILAC? as an example..

Hi /Lasse,

Here is one way (pseudo code - I didn't compile this):

public string MyMethod(out MyEnumType myEnum)
{
// do method stuff
myEnum = MyEnumType.CADDILAC;
return "I have a caddilac";
}

Call it like this:

MyEnumType anEnum;

string myString = MyMethod(out anEnum);

Console.WriteLine("Enum: {0}, String: {1}", anEnum, myString);

Other possibilities include creating a struct with the enum and string

type and returning the struct, returning an enum from the method and making the
string an out parameter, or making both the enum and the string out
parameters.

Joe
--
http://www.csharp-station.com

Nov 15 '05 #3

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

Similar topics

7
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...
1
by: Anonieko Ramos | last post by:
Answer: http://weblogs.asp.net/tims/archive/2004/04/02/106310.aspx by Tim Sneath I've come across the situation on a number of occasions when coding where I've wanted to convert from a string...
7
by: Henke | last post by:
Hi! Has anyone a nice way to connect a enum to a string value. Now I declare a const string in the same class as my enum is defined. But I doubt that's the "object oriented" way of doing it. Any...
10
by: Sanjay Pais | last post by:
I have a class: public static class HOW_GOOD { static string mstrHowGood = { "A", "G", "NTB", "T" };
3
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" }
7
by: Daren Hawes | last post by:
Hi, I am creating a function for a payment gateway and wondered is there a way for a function to return 2 or more values. IE Function Payment(ByVal ccNumber as String, Byval Amount as...
2
by: Sterling | last post by:
Any ideas why the following error occurs when "BuildExplicitAccessWithName" is called? PInvoke restriction: can not return variants ----------------------------------------------------- ...
2
by: Bishman | last post by:
Hi, I am new to C# so forgive my ignorance. I need to write a month 'number' to a DB, ie January = 1, March=3 etc etc... I have the month description in a combo box. I used an enum " ...
8
by: tony | last post by:
Hello! I have below a for loop and a switch in the for loop. I have also a enum called colBlowStep with some values. I have also an array called m_columnBlowStep with some strings. All items in...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.