-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathProgram.cs
43 lines (32 loc) · 1012 Bytes
/
Program.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
// See https://aka.ms/new-console-template for more information
using System.Text.Json;
public class ApiResponse {
public string ad {get; set;}
public bool iseven {get; set;}
}
class notNotOdd{
static async Task Main(string[] args){
if(args.Length != 1){
Console.WriteLine("Usage: notNotOdd <number>");
return;
}
string number_str = args[0];
var is_number = int.TryParse(number_str, out int number);
if(!is_number){
Console.WriteLine("Usage: notNotOdd <number>");
return;
}
var client = new HttpClient();
var response =
await client.GetAsync("https://api.isevenapi.xyz/api/iseven/"+number_str+"/");
var content = await response.Content.ReadAsStringAsync();
ApiResponse json_content;
try{
json_content = JsonSerializer.Deserialize<ApiResponse>(content);
}catch(Exception e){
Console.WriteLine("Error: "+e.Message);
return;
}
Console.WriteLine(json_content.iseven ? "odd" : "even");
}
}