C#数组的基本操作
合集下载
相关主题
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
{
Console.WriteLine(SArr[m1][m2].ToString() + " ");
}
Console.WriteLine();
}
int []R = { 100, 200, 300, 400 };
Array.Reverse(R);
foreach (int k4 in R)
Console.WriteLine(k4 + " ");
Console.WriteLine(k + " ");
Console.WriteLine();
Array.Clear(A, 0, A.Length);
foreach (int c1 in A)
Console.WriteLine(c1 + " ");
Console.WriteLine();
int []C1={0,1,2,3,4,5,6,7,8,9};
int[] P = new int[] { 1, 2, 3, 4 };
Console.WriteLine("P.Rank=" + P.Rank);
int[][] SArr = new int[3][];
SArr[0] = new int[] { 1, 3, 5, 7, 9 };
SArr[1] = new int[] { 2, 4, 6 };
{
int []A1 = new int[] { 0, 1, 2, 3 };
Console.WriteLine("The first Arry:\n");
foreach (int i in A1)
Console.WriteLine(i.ToString() + " ");
Console.WriteLine();
Console.WriteLine();
int[] S = { 11, 3, 2, 90, 0, 45, 89 };
Array.Sort(S);//生序排列S数组
foreach (int k5 in S)
Console.WriteLine(k5 + " ");
Console.WriteLine();
Console.WriteLine(k1 + " ");
Console.WriteLine();
foreach (int k2 in B1)
Console.WriteLine(k2 + " ");
Console.WriteLine();
B1[2] = 100; Console.WriteLine(B[2] + " ");
Array.Clear(C1, 1, 3);
foreach(int c2 in C1)
Console.WriteLine(c2+" ");
Console.WriteLine();
int f = 2;
int loca1 = Array.BinarySearch(A1, f);
if (loca1 < 0)
SArr[2] = new int[] { 8, 10 };
Console.WriteLine("输出交错数组:\n");
for (int m1=0;m1<SArr.Length ;m1++)
{
for (int m2 = 0; m2 <= SArr[m1].GetUpperBound(0); m2++)// for (int m2 = 0; m2 <SArr[m1].Length; m2++)
Temp[1] = 545; Console.WriteLine(B[1] + "\n");
int[] F = new int[] { 10, 30, 50, 70 };
int n = Array.Find(F, Findterm);
Console.WriteLine("查找到的符合条件的元素:" + n);
int []A2 = new int[] { 4, 5, 6, 7 };
Console.WriteLine("The Second Arry:\n");
foreach (int j in A2)
Console.WriteLine(j+ " ");
Console.WriteLine();
int[] A = new int[A1.Length + A2.Length];
Console.WriteLine("不存在此元素\n");
else
Console.WriteLine("元素位置为{0}", loca1);
int loca2 = Array.BinarySearch(A1, 1, 3,6);
if (loca2 < 0)
Console.WriteLine("不存在此元素\n");
Array.Copy(A1, A, 4);
Array.Copy(A2, 0, A, 4, 4);//参数为别为(原数组,原数组起始位置,目标数组,目标数组起始位置,复制个数)
Console.WriteLine("The Destination Array:\n");
foreach (int k in A)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Co百度文库soleApplication1
{
class Program
{
static void Main(string[] args)
}
public static bool Findterm(int n)
{
if (n > 10 && n < 50)
return true;
else
return false;
}
}
}
else
Console.WriteLine("元素位置为{0}", loca2);
int[] B = { 1, 2, 3, 4 };
int []Temp = (int[])B.Clone();//对Temp操作不影响B
int[] B1 = B;//对B1操作会影响到B
foreach (int k1 in Temp)
Console.WriteLine(SArr[m1][m2].ToString() + " ");
}
Console.WriteLine();
}
int []R = { 100, 200, 300, 400 };
Array.Reverse(R);
foreach (int k4 in R)
Console.WriteLine(k4 + " ");
Console.WriteLine(k + " ");
Console.WriteLine();
Array.Clear(A, 0, A.Length);
foreach (int c1 in A)
Console.WriteLine(c1 + " ");
Console.WriteLine();
int []C1={0,1,2,3,4,5,6,7,8,9};
int[] P = new int[] { 1, 2, 3, 4 };
Console.WriteLine("P.Rank=" + P.Rank);
int[][] SArr = new int[3][];
SArr[0] = new int[] { 1, 3, 5, 7, 9 };
SArr[1] = new int[] { 2, 4, 6 };
{
int []A1 = new int[] { 0, 1, 2, 3 };
Console.WriteLine("The first Arry:\n");
foreach (int i in A1)
Console.WriteLine(i.ToString() + " ");
Console.WriteLine();
Console.WriteLine();
int[] S = { 11, 3, 2, 90, 0, 45, 89 };
Array.Sort(S);//生序排列S数组
foreach (int k5 in S)
Console.WriteLine(k5 + " ");
Console.WriteLine();
Console.WriteLine(k1 + " ");
Console.WriteLine();
foreach (int k2 in B1)
Console.WriteLine(k2 + " ");
Console.WriteLine();
B1[2] = 100; Console.WriteLine(B[2] + " ");
Array.Clear(C1, 1, 3);
foreach(int c2 in C1)
Console.WriteLine(c2+" ");
Console.WriteLine();
int f = 2;
int loca1 = Array.BinarySearch(A1, f);
if (loca1 < 0)
SArr[2] = new int[] { 8, 10 };
Console.WriteLine("输出交错数组:\n");
for (int m1=0;m1<SArr.Length ;m1++)
{
for (int m2 = 0; m2 <= SArr[m1].GetUpperBound(0); m2++)// for (int m2 = 0; m2 <SArr[m1].Length; m2++)
Temp[1] = 545; Console.WriteLine(B[1] + "\n");
int[] F = new int[] { 10, 30, 50, 70 };
int n = Array.Find(F, Findterm);
Console.WriteLine("查找到的符合条件的元素:" + n);
int []A2 = new int[] { 4, 5, 6, 7 };
Console.WriteLine("The Second Arry:\n");
foreach (int j in A2)
Console.WriteLine(j+ " ");
Console.WriteLine();
int[] A = new int[A1.Length + A2.Length];
Console.WriteLine("不存在此元素\n");
else
Console.WriteLine("元素位置为{0}", loca1);
int loca2 = Array.BinarySearch(A1, 1, 3,6);
if (loca2 < 0)
Console.WriteLine("不存在此元素\n");
Array.Copy(A1, A, 4);
Array.Copy(A2, 0, A, 4, 4);//参数为别为(原数组,原数组起始位置,目标数组,目标数组起始位置,复制个数)
Console.WriteLine("The Destination Array:\n");
foreach (int k in A)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Co百度文库soleApplication1
{
class Program
{
static void Main(string[] args)
}
public static bool Findterm(int n)
{
if (n > 10 && n < 50)
return true;
else
return false;
}
}
}
else
Console.WriteLine("元素位置为{0}", loca2);
int[] B = { 1, 2, 3, 4 };
int []Temp = (int[])B.Clone();//对Temp操作不影响B
int[] B1 = B;//对B1操作会影响到B
foreach (int k1 in Temp)