Tuesday, November 5, 2013

How To Pass Array to a Web Method or Web Service Method

In this tutorial I will show you how to pass an array to a Method this can also work for web service method as well.

1. First we need to define a array and it some data in it


   1:              string[] array = new string[20];
   2:              for (int i = 0; i < 4; i++)
   3:              {
   4:                  array[i] = "This is number " + i;
   5:              }
 
 
Here I have define an array of type string, this can be of other type as well.

2. Now we will create a method that will accept a array of type string as a parameter


   1:  public void compressFiles(string[] objlistt)
   2:          {
   3:                  for (int i = 0; i <objlistt.Length; i++)
   4:                  {
   5:                  // your code here
   6:                  }
   7:          }
 
3. Now to send the array to the method, you will need to call that method like this


   1:  compressFiles(array);
 
I hope it was informative for you, and I would like to thank you for reading

No comments:

Post a Comment