Get the App
SLTechnology News&Howtos  ›  Development  › 

How to use the params,Ref,out keyword in C #

Shulou Source: shulou.com Published: 2022-06-03 16:35:07 09月28日 Update

This article mainly introduces how to use the params,Ref,out keyword in C#, which has a certain reference value. Interested friends can refer to it. I hope you will gain a lot after reading this article. Let's take a look at it.

You can study some of the original operations before these three keywords.

Using System;using System.Collections.Generic;using System.Text;namespace ParamsRefOut {class Program {static void ChangeValue (int I) {iTun5; Console.WriteLine ("The ChangeValue method changed the value" + i.ToString ());} static void Main (string [] args) {int I = 10; Console.WriteLine ("The value of I is" + i.ToString ()); ChangeValue (I) Console.WriteLine ("The value of I is" + i.ToString ()); Console.ReadLine ();}

Observe the running results and find out

The value has not been changed, that is to say, the principle of the operation at this time may be the same as the previous C language function operation.

This article mainly discusses params keyword, ref keyword, out keyword.

1) the params keyword, which is officially interpreted as used in cases where the length of the method parameter is uncertain. Sometimes you can't determine how many method parameters a method has, and you can use the params keyword to solve the problem.

Using System;using System.Collections.Generic;using System.Text;namespace ParamsRefOut {class number {public static void UseParams (params int [] list) {for (int iTuno)

Tags: Key keyword parameter method article Category similarity three that is value interest function primitive principle variable at the same time official situation more Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Information Docker Shulou Technology macOS NVidia