Notice
Recent Posts
Recent Comments
Link
스토리지
[3.18] 2차원 배열 연습 2 본문
1.
using System;
namespace Study07
{
public class App
{
enum eMaterial
{
GRASS = 100,
WATER,
SAND
}
public App()
{
int[,] arr = new int[5, 3];
Initialize(ref arr);
arr[1, 0] = arr[1, 1] = arr[1, 2] = (int)eMaterial.SAND;
for(int i = 0; i < arr.GetLength(0); i++)
{
for(int j = 0; j <arr.GetLength(1); j++)
{
Console.Write("{0}\t", (eMaterial)arr[i, j]);
}
Console.WriteLine();
}
}
private void Initialize(ref int[,] arr)
{
int d1 = arr.GetLength(0);
int d2 = arr.GetLength(1);
for(int i = 0; i < d1; i++)
{
for(int j = 0; j < d2; j++)
{
arr[i, j] = 100;
}
}
}
}
}
2.
using System;
namespace Study07
{
public class App
{
enum eMaterial
{
GRASS = 100,
SAND = 200,
WATER1 = 300,
WATER2 = 301,
WATER3 = 302,
WATER4 = 303,
WATER5 = 304
}
public App()
{
int[,] arr = new int[4, 5];
Initialize(ref arr);
arr[1, 0] = arr[2, 0] = arr[2, 1] = (int)eMaterial.SAND;
arr[2, 2] = arr[3, 2] = arr[3, 3] = arr[3, 4] = (int)eMaterial.SAND;
arr[0, 3] = (int)eMaterial.WATER4;
arr[0, 4] = (int)eMaterial.WATER5;
arr[1, 4] = (int)eMaterial.WATER3;
for (int i = 0; i < arr.GetLength(0); i++)
{
for (int j = 0; j < arr.GetLength(1); j++)
{
Console.Write("{0}\t", (eMaterial)arr[i, j]);
}
Console.WriteLine();
}
}
private void Initialize(ref int[,] arr)
{
int d1 = arr.GetLength(0);
int d2 = arr.GetLength(1);
for (int i = 0; i < d1; i++)
{
for (int j = 0; j < d2; j++)
{
arr[i, j] = 100;
}
}
}
}
}
3.
using System;
namespace Study07
{
public class App
{
enum eMaterial
{
GRASS = 100,
SAND = 200,
WATER1 = 300,
WATER2, //301
WATER3, //302
WATER4, //303
WATER5, //304
WATER6, //305
WATER7, //306
WATER8, //307
WATER9, //308
}
public App()
{
int[,] arr = new int[,]
{
{ 305, 306, 308 },
{ 302, 307, 100 },
{ 200, 200, 100 },
{ 100, 200, 200 }
};
for(int i = 0; i < arr.GetLength(0); i++)
{
for(int j = 0; j < arr.GetLength(1); j++)
{
Console.Write("{0}\t", (eMaterial)arr[i, j]);
}
Console.WriteLine();
}
}
}
}
4.
using System;
namespace Study07
{
public class App
{
enum eMaterial
{
GRASS = 100,
SAND = 200,
WATER1 = 300,
WATER2, //301
WATER3, //302
WATER4, //303
WATER5, //304
WATER6, //305
WATER7, //306
WATER8, //307
WATER9, //308
WATER10, //309
WATER11, //310
WATER12, //311
}
public App()
{
int[,] arr = new int[,]
{
{ 200, 200, 200 },
{ 100, 311, 310 },
{ 303, 309, 307 }
};
for(int i = 0; i < arr.GetLength(0); i++)
{
for(int j = 0; j < arr.GetLength(1); j++)
{
Console.Write("{0}\t", (eMaterial)arr[i, j]);
}
Console.WriteLine();
}
}
}
}
5.
using System;
namespace Study07
{
public class App
{
enum eMaterial
{
GRASS = 100,
SAND = 200,
WATER1 = 300,
WATER2, //301
WATER3, //302
WATER4, //303
WATER5, //304
WATER6, //305
WATER7, //306
WATER8, //307
WATER9, //308
WATER10, //309
WATER11, //310
WATER12, //311
}
public App()
{
int[,] arr = new int[,]
{
{ 310, 100, 200, 200 },
{ 306, 308, 100, 200 },
{ 307, 100, 100, 200 },
{ 200, 100, 200, 200 }
};
for(int i = 0; i < arr.GetLength(0); i++)
{
for(int j = 0; j < arr.GetLength(1); j++)
{
Console.Write("{0}\t", (eMaterial)arr[i, j]);
}
Console.WriteLine();
}
}
}
}
6.
using System;
namespace Study07
{
public class App
{
enum eMaterial
{
GRASS = 100,
SAND = 200,
WATER1 = 300,
WATER2, //301
WATER3, //302
WATER4, //303
WATER5, //304
WATER6, //305
WATER7, //306
WATER8, //307
WATER9, //308
WATER10, //309
WATER11, //310
WATER12, //311
}
public App()
{
int[,] arr = new int[,]
{
{ 200, 100, 100, 100 },
{ 200, 100, 100, 100 },
{ 200, 100, 100, 100 },
{ 100, 100, 100, 100 }
};
for(int i = 0; i < arr.GetLength(0); i++)
{
for(int j = 0; j < arr.GetLength(1); j++)
{
Console.Write("{0}\t", (eMaterial)arr[i, j]);
}
Console.WriteLine();
}
}
}
}
7.
using System;
namespace Study07
{
public class App
{
enum eMaterial
{
GRASS = 100,
SAND = 200,
WATER1 = 300,
WATER2, //301
WATER3, //302
WATER4, //303
WATER5, //304
WATER6, //305
WATER7, //306
WATER8, //307
WATER9, //308
WATER10, //309
WATER11, //310
WATER12, //311
}
public App()
{
int[,] arr = new int[,]
{
{ 200, 200, 200, 100 },
{ 200, 200, 200, 200 },
{ 100, 100, 100, 200 },
{ 100, 100, 100, 100 }
};
for(int i = 0; i < arr.GetLength(0); i++)
{
for(int j = 0; j < arr.GetLength(1); j++)
{
Console.Write("{0}\t", (eMaterial)arr[i, j]);
}
Console.WriteLine();
}
}
}
}
8.
using System;
namespace Study07
{
public class App
{
enum eMaterial
{
GRASS = 100,
SAND = 200,
WATER1 = 300,
WATER2, //301
WATER3, //302
WATER4, //303
WATER5, //304
WATER6, //305
WATER7, //306
WATER8, //307
WATER9, //308
WATER10, //309
WATER11, //310
WATER12, //311
WATER13, //312
WATER14, //313
WATER15, //314
WATER16, //315
}
public App()
{
int[,] arr = new int[,]
{
{ 100, 311, 315 },
{ 100, 314, 307 },
{ 312, 313, 100 }
};
for(int i = 0; i < arr.GetLength(0); i++)
{
for(int j = 0; j < arr.GetLength(1); j++)
{
Console.Write("{0}\t", (eMaterial)arr[i, j]);
}
Console.WriteLine();
}
}
}
}
9.
using System;
namespace Study07
{
public class App
{
enum eMaterial
{
GRASS = 100,
SAND = 200,
WATER1 = 300,
WATER2, //301
WATER3, //302
WATER4, //303
WATER5, //304
WATER6, //305
WATER7, //306
WATER8, //307
WATER9, //308
WATER10, //309
WATER11, //310
WATER12, //311
WATER13, //312
WATER14, //313
WATER15, //314
WATER16, //315
WATER17, //316
}
public App()
{
int[,] arr = new int[,]
{
{ 100, 100, 100, 100 },
{ 100, 100, 100, 100 },
{ 100, 100, 100, 316 },
{ 100, 100, 311, 315 }
};
for(int i = 0; i < arr.GetLength(0); i++)
{
for(int j = 0; j < arr.GetLength(1); j++)
{
Console.Write("{0}\t", (eMaterial)arr[i, j]);
}
Console.WriteLine();
}
}
}
}
10.
using System;
namespace Study07
{
public class App
{
enum eMaterial
{
GRASS = 100,
SAND = 200,
WATER1 = 300,
WATER2, //301
WATER3, //302
WATER4, //303
WATER5, //304
WATER6, //305
WATER7, //306
WATER8, //307
WATER9, //308
WATER10, //309
WATER11, //310
WATER12, //311
WATER13, //312
WATER14, //313
WATER15, //314
WATER16, //315
WATER17, //316
WATER18, //317
}
public App()
{
int[,] arr = new int[,]
{
{ 200, 200, 100, 100 },
{ 200, 100, 100, 100 },
{ 311, 317, 317, 310 }
};
for(int i = 0; i < arr.GetLength(0); i++)
{
for(int j = 0; j < arr.GetLength(1); j++)
{
Console.Write("{0}\t", (eMaterial)arr[i, j]);
}
Console.WriteLine();
}
}
}
}
'Unity > 수업내용(C#)' 카테고리의 다른 글
[3.18] 2차원 배열 연습 4 - Isometric View (0) | 2021.03.18 |
---|---|
[3.18] 2차원 배열 연습 3 (0) | 2021.03.18 |
[3.18] 2차원 배열 연습 1 (0) | 2021.03.18 |
[3.18] Indexer (0) | 2021.03.18 |
[3.18] GUID 및 Equatable (0) | 2021.03.18 |
Comments