📄 program.cs
字号:
using System;
public class SamplesArray
{
public static void Main()
{
// Creates and initializes a new integer array and a new Object array.
int[] myIntArray = new int[5] { 1, 2, 3, 4, 5 };
Object[] myObjArray = new Object[5] { 26, 27, 28, 29, 30 };
// Prints the initial values of both arrays.
Console.WriteLine("Initially,");
Console.Write("integer array:");
PrintValues(myIntArray);
Console.Write("Object array: ");
PrintValues(myObjArray);
// Copies the first two elements from the integer array to the Object array.
Array.Copy(myIntArray, myObjArray, 2);
// Prints the values of the modified arrays.
Console.WriteLine("\nAfter copying the first two elements of the integer array to the Object array,");
Console.Write("integer array:");
PrintValues(myIntArray);
Console.Write("Object array: ");
PrintValues(myObjArray);
// Copies the last two elements from the Object array to the integer array.
Array.Copy(myObjArray, myObjArray.GetUpperBound(0) - 1, myIntArray, myIntArray.GetUpperBound(0) - 1, 2);
// Prints the values of the modified arrays.
Console.WriteLine("\nAfter copying the last two elements of the Object array to the integer array,");
Console.Write("integer array:");
PrintValues(myIntArray);
Console.Write("Object array: ");
PrintValues(myObjArray);
}
public static void PrintValues(object[] myArr)
{
foreach (Object i in myArr)
{
Console.Write("\t{0}", i);
}
Console.WriteLine();
}
public static void PrintValues(int[] myArr)
{
foreach (int i in myArr)
{
Console.Write("\t{0}", i);
}
Console.WriteLine();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -