|
此文章由机器翻译。 将光标移到文章的句子上,以查看原文。 更多信息。
|
译文
原文
|
Action<T1, T2, T3, T4> 委托
命名空间: System
程序集: mscorlib(在 mscorlib.dll 中)
public delegate void Action<in T1, in T2, in T3, in T4>( T1 arg1, T2 arg2, T3 arg3, T4 arg4 )
类型参数
- in T1
此委托封装的方法的第一个参数类型。 该类型参数是逆变。即可以使用指定的类型或派生程度更低的类型。有关协变和逆变的更多信息,请参见泛型中的协变和逆变。
- in T2
此委托封装的方法的第二个参数类型。
- in T3
此委托封装的方法的第三个参数类型。
- in T4
此委托封装的方法的第四个参数类型。
参数
- arg1
- 类型:T1
此委托封装的方法的第一个参数。
- arg2
- 类型:T2
此委托封装的方法的第二个参数。
- arg3
- 类型:T3
此委托封装的方法的第三个参数。
- arg4
- 类型:T4
此委托封装的方法的第四个参数。
说明 |
|---|
using System; delegate void StringCopy(string[] stringArray1, string[] stringArray2, int indexToStart, int numberToCopy); public class TestDelegate { public static void Main() { string[] ordinals = {"First", "Second", "Third", "Fourth", "Fifth", "Sixth", "Seventh", "Eighth", "Ninth", "Tenth"}; string[] copiedOrdinals = new string[ordinals.Length]; StringCopy copyOperation = CopyStrings; copyOperation(ordinals, copiedOrdinals, 3, 5); foreach (string ordinal in copiedOrdinals) Console.WriteLine(String.IsNullOrEmpty(ordinal) ? "<None>" : ordinal); } private static void CopyStrings(string[] source, string[] target, int startPos, int number) { if (source.Length != target.Length) throw new IndexOutOfRangeException("The source and target arrays must have the same number of elements."); for (int ctr = startPos; ctr <= startPos + number - 1; ctr++) target[ctr] = String.Copy(source[ctr]); } }
using System; public class TestAction4 { public static void Main() { string[] ordinals = {"First", "Second", "Third", "Fourth", "Fifth", "Sixth", "Seventh", "Eighth", "Ninth", "Tenth"}; string[] copiedOrdinals = new string[ordinals.Length]; Action<string[], string[], int, int> copyOperation = CopyStrings; copyOperation(ordinals, copiedOrdinals, 3, 5); foreach (string ordinal in copiedOrdinals) Console.WriteLine(String.IsNullOrEmpty(ordinal) ? "<None>" : ordinal); } private static void CopyStrings(string[] source, string[] target, int startPos, int number) { if (source.Length != target.Length) throw new IndexOutOfRangeException("The source and target arrays must have the same number of elements."); for (int ctr = startPos; ctr <= startPos + number - 1; ctr++) target[ctr] = String.Copy(source[ctr]); } }
using System; public class TestAnonymousMethod { public static void Main() { string[] ordinals = {"First", "Second", "Third", "Fourth", "Fifth", "Sixth", "Seventh", "Eighth", "Ninth", "Tenth"}; string[] copiedOrdinals = new string[ordinals.Length]; Action<string[], string[], int, int> copyOperation = delegate(string[] s1, string[] s2, int pos, int num) { CopyStrings(s1, s2, pos, num); }; copyOperation(ordinals, copiedOrdinals, 3, 5); foreach (string ordinal in copiedOrdinals) Console.WriteLine(String.IsNullOrEmpty(ordinal) ? "<None>" : ordinal); } private static void CopyStrings(string[] source, string[] target, int startPos, int number) { if (source.Length != target.Length) throw new IndexOutOfRangeException("The source and target arrays must have the same number of elements."); for (int ctr = startPos; ctr <= startPos + number - 1; ctr++) target[ctr] = String.Copy(source[ctr]); } }
using System; public class TestLambdaExpression { public static void Main() { string[] ordinals = {"First", "Second", "Third", "Fourth", "Fifth", "Sixth", "Seventh", "Eighth", "Ninth", "Tenth"}; string[] copiedOrdinals = new string[ordinals.Length]; Action<string[], string[], int, int> copyOperation = (s1, s2, pos, num) => CopyStrings(s1, s2, pos, num); copyOperation(ordinals, copiedOrdinals, 3, 5); foreach (string ordinal in copiedOrdinals) Console.WriteLine(String.IsNullOrEmpty(ordinal) ? "<None>" : ordinal); } private static void CopyStrings(string[] source, string[] target, int startPos, int number) { if (source.Length != target.Length) throw new IndexOutOfRangeException("The source and target arrays must have the same number of elements."); for (int ctr = startPos; ctr <= startPos + number - 1; ctr++) target[ctr] = String.Copy(source[ctr]); } }
Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008(不支持服务器核心角色), Windows Server 2008 R2(支持带 SP1 或更高版本的服务器核心角色;不支持 Itanium)
.NET Framework 并不是对每个平台的所有版本都提供支持。有关支持的版本的列表,请参见.NET Framework 系统要求。
说明