Use ref and out to pass the Array

Source: Internet
Author: User

C # Learning Experience: Using ref and out to pass the Array (downmoon), I hope to share with you
1. Like all out parameters, an out parameter of the array type must be assigned a value first, that is, it must be assigned a value by the receiver. For example:

Public static void mymethod (Out int [] ARR)
{
Arr = new int [10]; // clear Delegate of array arr
}
2. Like all ref parameters, the ref parameter of the array type must be explicitly assigned by the caller. Therefore, it is not necessary for the receiver to explicitly assign values. You can change the ref parameter of the array type to the result of the call. For example, you can assign a null value to an array or initialize it as another array. For example:

Public static void mymethod (ref int [] ARR)
{
Arr = new int [10]; // arr is initialized to a new array.
}
The following two examples illustrate the usage differences between out and ref in passing arrays to methods.

Example 1
In this example, declare the array myarray In the caller (main method) and initialize the array in the fillarray method. Then, the array elements are returned to the caller and displayed.

Using system;
Class testout
{
Static public void fillarray (Out int [] myarray)
{
// Initialize the Array (required ):
Myarray = new int [5] {1, 2, 3, 4, 5 };
}

Static public void main ()
{
Int [] myarray; // initialize the Array (not required !)

// Pass the array to the caller (using the out method:
Fillarray (Out myarray );

// Display array elements
Console. writeline (the array element is :);
For (INT I = 0; I <myarray. length; I ++)
Console. writeline (myarray [I]);
}
}
Output
The array element is:
1
2
3
4
5
Example 2
In this example, initialize the array myarray In the caller (main method) and pass it to the fillarray method by using the ref parameter. Update some array elements in the fillarray method. Then, the array elements are returned to the caller and displayed.

Using system;
Class testref
{
Public static void fillarray (ref int [] ARR)
{
// Create a new array as needed (not required)
If (ARR = NULL)
Arr = new int [10];
// Otherwise, fill in the array.
Arr [0] = 123;
Arr [4] = 1024;
}

Static public void main ()
{
// Initialize the array:
Int [] myarray = {1, 2, 3, 4, 5 };

// Use ref to pass the array:
Fillarray (ref myarray );

// Display the updated array elements:
Console. writeline (the array element is :);
For (INT I = 0; I <myarray. length; I ++)
Console. writeline (myarray [I]);
}
}
Output
The array element is:
123
2
3
4
1024

 

 

1. Overview of Web Services
Web services can be used by a single application internally or by external applications over the Internet. Web services enables heterogeneous systems to run collaboratively as single computing network resources because they can be accessed through standard interfaces.
Web Services does not pursue the common code portability function, but provides a feasible solution for achieving data and system interoperability. Web Services uses XML-based message processing as the basic data communication method to help eliminate differences between systems using different component models, operating systems, and programming languages. Developers can create applications that combine Web services from various platforms in the same way as they used components when creating distributed applications in the past.
One of the core features of Web Services is the high abstraction between service implementation and use. By using the XML-based message processing mechanism, the Web Services Client and the web services provider do not need to know each other except the input, output, and location.
Web Services releases a platform-independent API that can be called through the Web. That is to say, on any platform you like, you can use programming methods to call this application through the web for web-based distributed computing and processing. The Web services platform is a set of standards that define how applications implement interoperability on the web. The Web Services Platform uses XML to represent the basic format of data and XML Schema (XSD) developed by W3C as its data type system.
The three core technical specifications that constitute the web services platform are SOAP, WSDL, and UDDI. The SOAP specification defines the SOAP message format and how to use soap through the HTTP protocol to execute web services calls. The Web Services Description Language (WSDL) is used to describe Web Services. Because it is based on XML, the WSDL document is machine readable and human readable. The UDDI (unified description, discovery, and integration protocols) Standard defines the release and Discovery Methods of Web Services.
From a technical point of view, Web services can be considered as a web object. Therefore, it has all the advantages promised by the object technology. At the same time, web services is based on XML-based and open web specification technology. Therefore, it is more open than any existing object technology.

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.