-
Notifications
You must be signed in to change notification settings - Fork 183
/
22 - Day 21 - Generics.cs
44 lines (36 loc) · 1.02 KB
/
22 - Day 21 - Generics.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
// ========================
// Information
// ========================
// Direct Link: https://www.hackerrank.com/challenges/30-generics/problem
// Difficulty: Easy
// Max Score: 30
// Language: C#
// ========================
// Solution
// ========================
using System;
class Printer {
// Name: PrintArray
// Print each element of the generic array on a new line. Do not return anything.
// @param A generic array
// Write your code here
static void PrintArray < Element > (Element[] array) {
foreach(var element in array) {
Console.WriteLine(element);
}
}
static void Main(string[] args) {
int n = Convert.ToInt32(Console.ReadLine());
int[] intArray = new int[n];
for (int i = 0; i < n; i++) {
intArray[i] = Convert.ToInt32(Console.ReadLine());
}
n = Convert.ToInt32(Console.ReadLine());
string[] stringArray = new string[n];
for (int i = 0; i < n; i++) {
stringArray[i] = Console.ReadLine();
}
PrintArray < Int32 > (intArray);
PrintArray < String > (stringArray);
}
}