Im using an C#'s user defined private function on which i want to return more
than one value (like int and string[] ) and from that function.
please let me know in advance..
assankhan Ismail 4 1950
Hi Dear AssanKhan Ismail,
You can return more than one (1) value or type by constructing a class and
returning that class in your function.
for example:
========
Construct a class like this with 4 Different Types like bool, int, double,
string
public class Different_Types
{
public Different_Types ()
{
//
// TODO: Add constructor logic here
//
}
int m_int;
string m_str;
bool m_bool;
double m_double;
public int PassInteger
{
get {return m_int;}
set {m_int = value;}
}
public string PassString
{
get {return m_str;}
set {m_str = value;}
}
public bool PassBoolean
{
get {return m_bool;}
set {m_bool = value;}
}
public double PassDouble
{
get {return m_double;}
set {m_double = value;}
}
}
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Then Create you Function which return 4 Different Types of Values ( but all
the 4 different types of values pass through the object which is created the
class above
function name is = Returen_Many_Va lues_CLASS
it returns the type of object = Different_Types
for this object you have created a class above
public Different_Types Returen_Many_Va lues_CLASS()
{
Different_Types diff_types = new Different_Types ();
diff_types.Pass Boolean=false;
diff_types.Pass Double=3.142;
diff_types.Pass Integer=67;
diff_types.Pass String="Venkat" ;
return diff_types;
}
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Use the above function in a button click and populate 4 different textboxes
for this you have to place 4 different textboxes and one command button
private void button1_Click(o bject sender, System.EventArg s e)
{
this.textBox1.T ext=Returen_Man y_Values_CLASS( ).PassBoolean.T oString();
this.textBox2.T ext=Returen_Man y_Values_CLASS( ).PassDouble.To String();
this.textBox3.T ext=Returen_Man y_Values_CLASS( ).PassInteger.T oString();
this.textBox4.T ext=Returen_Man y_Values_CLASS( ).PassString;
}
You can test this one in one dummy windows application in .net
for Anything and Everything, Please Let Me Know
bye
Venkat_KL
Hi Dear AssanKhan Ismail,
You can even do with struct
for that first create a struct like below
struct MyStruct
{
public int x;
public string y;
}
------------------------------------------------------------------------------------------------
then create you function which returns you struct
private MyStruct MyStruct_Return ing_Method()
{
MyStruct ms = new MyStruct();
ms.x=121;
ms.y="venkat";
return ms;
}
Name of the Function=MyStru ct_Returning_Me thod
Return type=MyStruct
Give value to both the type like int and string (I have given as 121 &
"venkat")
------------------------------------------------------------------------------------------------
Place two textboxex and one command button on the windows form to test
In the button click event write this code
private void button1_Click(o bject sender, System.EventArg s e)
{
this.textBox1.T ext=MyStruct_Re turning_Method( ).x.ToString();
this.textBox2.T ext=MyStruct_Re turning_Method( ).y;
}
Test and for anything and everything, please let me know
bye
Venkat_KL
Hi Dear Venkat
Your Code is very helpful to me.
Thanks a lot for your timely help.
bye
assankhan
"Venkat_KL" wrote: Hi Dear AssanKhan Ismail,
You can return more than one (1) value or type by constructing a class and returning that class in your function.
for example: ========
Construct a class like this with 4 Different Types like bool, int, double, string
public class Different_Types { public Different_Types () { // // TODO: Add constructor logic here // }
int m_int; string m_str; bool m_bool; double m_double;
public int PassInteger { get {return m_int;} set {m_int = value;} }
public string PassString { get {return m_str;} set {m_str = value;} } public bool PassBoolean { get {return m_bool;} set {m_bool = value;} } public double PassDouble { get {return m_double;} set {m_double = value;} } }
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Then Create you Function which return 4 Different Types of Values ( but all the 4 different types of values pass through the object which is created the class above
function name is = Returen_Many_Va lues_CLASS
it returns the type of object = Different_Types for this object you have created a class above
public Different_Types Returen_Many_Va lues_CLASS() { Different_Types diff_types = new Different_Types (); diff_types.Pass Boolean=false; diff_types.Pass Double=3.142; diff_types.Pass Integer=67; diff_types.Pass String="Venkat" ; return diff_types; }
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Use the above function in a button click and populate 4 different textboxes
for this you have to place 4 different textboxes and one command button
private void button1_Click(o bject sender, System.EventArg s e) { this.textBox1.T ext=Returen_Man y_Values_CLASS( ).PassBoolean.T oString(); this.textBox2.T ext=Returen_Man y_Values_CLASS( ).PassDouble.To String(); this.textBox3.T ext=Returen_Man y_Values_CLASS( ).PassInteger.T oString(); this.textBox4.T ext=Returen_Man y_Values_CLASS( ).PassString;
}
You can test this one in one dummy windows application in .net
for Anything and Everything, Please Let Me Know
bye Venkat_KL
Hi Dear Venkat
Your alternate Coding sample adds more values to my doubts.
Thanks a lot for your timely help.
bye
assankhan
"Venkat_KL" wrote: Hi Dear AssanKhan Ismail,
You can even do with struct
for that first create a struct like below
struct MyStruct { public int x; public string y; } ------------------------------------------------------------------------------------------------ then create you function which returns you struct
private MyStruct MyStruct_Return ing_Method() { MyStruct ms = new MyStruct(); ms.x=121; ms.y="venkat"; return ms; }
Name of the Function=MyStru ct_Returning_Me thod Return type=MyStruct
Give value to both the type like int and string (I have given as 121 & "venkat")
------------------------------------------------------------------------------------------------
Place two textboxex and one command button on the windows form to test
In the button click event write this code private void button1_Click(o bject sender, System.EventArg s e) { this.textBox1.T ext=MyStruct_Re turning_Method( ).x.ToString(); this.textBox2.T ext=MyStruct_Re turning_Method( ).y; }
Test and for anything and everything, please let me know
bye Venkat_KL This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Neal Coombes |
last post by:
Posted to comp.lang.c++.moderated with little response. Hoping for
better from the unmoderated groups:
-------- Original Message --------
Subject: Return appropriately by value, (smart) pointer, or reference
Date: 27 Aug 2005 15:13:23 -0400
From: Neal Coombes <nealc@trdlnk.com>
Organization: Aioe.org NNTP Server
To: (Usenet)
Newsgroups: comp.lang.c++.moderated
|
by: Ravindranath Gummadidala |
last post by:
Hi All:
I am trying to understand the C function call mechanism. Please bear with
me as I state what I know:
"every invocation of a function causes a frame for that function to be
pushed on stack. this contains the arguments this function was called
with, address to return to after return from this function (the location
in the previous stack frame), location of previous frame on stack (base or
start of this frame) and local variables...
|
by: lovecreatesbeauty |
last post by:
I ever missed a `return' statement when write a function `int
HighDigit(Num)' to get the highest digit of an integer.
But even if the `return' statement is ignored the function still can
obtain an `correct' return value when the argument `Num' is larger than
or equal to the Macro `NUM_SYS'.
If the argument is less than the Macro, the function without a `return'
get an undefined value. I've made a test on Ms Windows 2000 and VC 6.
|
by: Ed Jay |
last post by:
<disclaimer>js newbie</disclaimer>
My page has a form comprised of several radio buttons. I want to poll the
buttons to determine which button was selected and convert its value to a
string. I then want to use the string on the same page.
My script is:
function checkRadio(field) {
for(var i=0; i < field.length; i++) {
|
by: gregory_may |
last post by:
Is it possible to return "nothing" from an Integer function? This seems to
give me "0" rather than "nothing".
Private Function MyFunction() As Integer
Return Nothing
End Function
| |
by: colmkav |
last post by:
Can someone tell me how I can access the return value of a function
called from Oracle as opposed to a store proc from oracle? my oracle
function is get_num_dates_varposfile. I am only used to using this
method with store procs that dont return a value back to Access. Hope
this makes sense.
Set Cmd = New Command
With Cmd
Set .ActiveConnection = get_XE_Conn 'makes a connection
Oracle XE
|
by: Terry Olsen |
last post by:
How do I get this to work? It always returns False, even though I can see
"This is True!" in the debug window. Do I have to invoke functions
differently than subs?
Private Delegate Function IsLvItemCheckedDelegate(ByVal ClientID As Integer)
As Boolean
Private Function IsLvItemChecked(ByVal ClientID As Integer) As Boolean
If lvServers.InvokeRequired = True Then
lvServers.Invoke(New IsLvItemCheckedDelegate(AddressOf IsLvItemChecked),...
|
by: Davy |
last post by:
Hi all,
I am writing a function, which return the pointer of the int. But it
seems to be wrong. Any suggestion?
int * get_p_t(int t) {
return &t;
}
int main()
|
by: Carl Forsman |
last post by:
there are 2 ways to return a value from a function
====================
1) passing a reference as parameter - the following will return time
void Table::Get(char* FieldName, *SYSTEMTIME time)
{
_variant_t vtValue;
vtValue = m_Rec->Fields->GetItem(FieldName)->GetValue();
if (vtValue.vt == VT_NULL) {
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
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 then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |