Skip to content

Instantly share code, notes, and snippets.

@JJack55on
Created April 10, 2025 15:23
Show Gist options
  • Save JJack55on/27c1ec3a6975fa50abb22f9487d113df to your computer and use it in GitHub Desktop.
Save JJack55on/27c1ec3a6975fa50abb22f9487d113df to your computer and use it in GitHub Desktop.
namespace array;
class Program
{
public static void Main(string[] args)
{
int[] A = { 0, 1, 2, 3, 4, 5, 6, 7, 8 };
Console.WriteLine(A.Length);//получение длины массива
}
public static class MyArray
{
static int[] myArray;
static int arrayLength;
//инициализация массива А
public static int[] Initialize(int[] A)
{
return (int[]) A.Clone();
}
//получение длины массива
public static void SetArray(int[] A)
{
myArray = A;
arrayLength = A.Length;
Console.WriteLine($"array length = {arrayLength}");
}
//получение элемента по индексу
public static int GetByIndex(int [] A , int index)
{
if (index < 0 || index >= arrayLength)
throw new IndexOutOfRangeException("индекс за пределом");
return myArray[index];
}
// дописать в конец myArray переданый element
public static void Add(int[] A ,int element)
{
Console.WriteLine(myArray[A.Length - 1]); // 5 - первый с конца или последний элемент
Console.WriteLine(myArray[A.Length - 2]);
arrayLength++;
}
// сортировка
public static void SortArray()
{
int[] sortedArray = new int[arrayLength];
sortedArray = myArray;
public static int temp;
for (int i = 0; i < - 1; i++)
{
for (int j = i + 1; j < myArray.Length; j++)
{
if (myArray[i] > myArray[j])
{
temp = myArray[i];
myArray[i] = myArray[j];
myArray[j] = temp;
}
}
}
}
}
}

Comments are disabled for this gist.