473,387 Members | 1,534 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,387 software developers and data experts.

String array Function

hallo,

I have a function which takes 2 values as input and i want to return that 2 values, so how should write the return statement to return 2 values of String array. I also i should retrieve these values in a button click event. here is my code.
Expand|Select|Wrap|Line Numbers
  1. public String newop(string userna,string pwd)
  2.         {
  3.            cwe_pro.GetFolderContentRequestType preq = new cwe_pro.GetFolderContentRequestType();
  4.            cwe_pro.GetFolderContentReplyType pres = new cwe_pro.GetFolderContentReplyType();
  5.             try
  6.             {
  7.                 preq.depth = 0;
  8.                 preq.folderId = docid;
  9.                 ws.Url = "http://www.cwe-projects.eu/bscw/bscw.cgi";
  10.                 ws.Credentials = new System.Net.NetworkCredential(userna, pwd);
  11.                 pres = ws.GetFolderContent(preq);
  12.                 XmlDocument doc = new XmlDocument();
  13.                 doc.LoadXml(pres.folderContent);
  14.                 XmlNodeList ni = doc.GetElementsByTagName("dcterms:modified");
  15.                 st = ni[0].InnerText;
  16.                 if (st.Equals(lmod))
  17.                 {
  18.  
  19.                     MessageBox.Show("No modification In the File");
  20.                     textBox3.Visible = false;
  21.                     groupBox3.Visible = true;
  22.  
  23.                 }
  24.                 else
  25.                 {
  26.  
  27.                     MessageBox.Show("Last modified by another user :" + st);
  28.                     textBox3.Visible = false;
  29.                     groupBox3.Visible = true;
  30.  
  31.  
  32.                 }
  33.             }
  34.             catch (Exception e1)
  35.             {
  36.                 MessageBox.Show(e1.ToString());
  37.  
  38.                 return;
  39.             }
  40.       }
  41.  
  42. this is my function and how should write the return statement that return a array of those two values username and pwd. i have retreive these 2 values usrname and pwd in button click event.
  43.  
  44. private void button3_Click(object sender, EventArgs e)
  45.         {
  46. }
  47.  
sorry iam newbie to c# i dont know this simple task itself. any idea ?..

Thank you.
Dinesh.
Nov 21 '08 #1
5 1381
nukefusion
221 Expert 100+
You could use "out" parameters. You declare two parameters and mark them with the keyword "out", then make sure you assign them before the end of the method:

Expand|Select|Wrap|Line Numbers
  1.        public void newop(string userna, string pwd, out string resultString1, out string resultString2)
  2.        {
  3.            // make sure you assign the results to the two Out parameters before the method exits
  4.            resultString1 = result1;
  5.            resultString2 = result2;
  6.        }
You would then call the method like this:

Expand|Select|Wrap|Line Numbers
  1.  public void Test()
  2.        {
  3.            string result1;
  4.            string result2;
  5.            newop("user", "pass", out result1, out result2);
  6.        }
Result1 and result2 now contain your return values.

Alternatively, if you really want, you can return the results in a generic list (or another collection type):

Expand|Select|Wrap|Line Numbers
  1. public List<string> newop(string userna,string pwd)
  2.            {
  3.                List<string> results = new List<string>();
  4.                results.Add(string1);
  5.                results.Add(string2);
  6.                return results;
  7.            }
Nov 21 '08 #2
r035198x
13,262 8TB
The last return would need to be
Expand|Select|Wrap|Line Numbers
  1. return results;
Nov 21 '08 #3
nukefusion
221 Expert 100+
The last return would need to be
Expand|Select|Wrap|Line Numbers
  1. return results;
Thanks r035198x, must have missed that. I've corrected the code sample.
Nov 21 '08 #4
r035198x
13,262 8TB
Thanks r035198x, must have missed that. I've corrected the code sample.
No problem.

r035198x <-----Nitpicky .NET village idiot who knows nothing about .NET
Nov 21 '08 #5
You could use "out" parameters. You declare two parameters and mark them with the keyword "out", then make sure you assign them before the end of the method:

Expand|Select|Wrap|Line Numbers
  1.        public void newop(string userna, string pwd, out string resultString1, out string resultString2)
  2.        {
  3.            // make sure you assign the results to the two Out parameters before the method exits
  4.            resultString1 = result1;
  5.            resultString2 = result2;
  6.        }
You would then call the method like this:

Expand|Select|Wrap|Line Numbers
  1.  public void Test()
  2.        {
  3.            string result1;
  4.            string result2;
  5.            newop("user", "pass", out result1, out result2);
  6.        }
Result1 and result2 now contain your return values.

Alternatively, if you really want, you can return the results in a generic list (or another collection type):

Expand|Select|Wrap|Line Numbers
  1. public List<string> newop(string userna,string pwd)
  2.            {
  3.                List<string> results = new List<string>();
  4.                results.Add(string1);
  5.                results.Add(string2);
  6.                return results;
  7.            }
HI nuke ,

Thank you for ur reply. It work fine.

Dinesh.
Nov 21 '08 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

9
by: Danny | last post by:
HI again Is there a nifty function in access that will: 1. return the amount of occurances of a small string within a larger string? this<br>is<br>a<br>test would return 3 for <br>
0
by: Tom Warren | last post by:
I found a c program called similcmp on the net and converted it to vba if anybody wants it. I'll post the technical research on it if there is any call for it. It looks like it could be a useful...
7
by: al | last post by:
char s = "This string literal"; or char *s= "This string literal"; Both define a string literal. Both suppose to be read-only and not to be modified according to Standard. And both have...
4
by: songkv | last post by:
Hi, I am trying to reassign an array of char to a string literal by calling a function. In the function I use pointer-to-pointer since I want to reassign the "string array pointer" to the string...
3
by: Goh, Yong Kwang | last post by:
I'm trying to create a function that given a string, tokenize it and put into a dynamically-sized array of char* which is in turn also dynamically allocated based on the string token length. I...
4
by: Simon Schaap | last post by:
Hello, I have encountered a strange problem and I hope you can help me to understand it. What I want to do is to pass an array of chars to a function that will split it up (on every location where...
23
by: Nascimento | last post by:
Hello, How to I do to return a string as a result of a function. I wrote the following function: char prt_tralha(int num) { int i; char tralha;
14
by: Bob | last post by:
I have a function that takes in a list of IDs (hundreds) as input parameter and needs to pass the data to another step as a comma delimited string. The source can easily create this list of IDs in...
12
by: Pascal | last post by:
hello and soory for my english here is the query :"how to split a string in a random way" I try my first shot in vb 2005 express and would like to split a number in several pieces in a random way...
6
by: Andrea | last post by:
Hi, suppose that I have a string that is an hexadecimal number, in order to print this string I have to do: void print_hex(unsigned char *bs, unsigned int n){ int i; for (i=0;i<n;i++){...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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...

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.