Browse Source

Add C# to list

master
Matei-Alexandru Gardus 9 months ago
parent
commit
bbffaa8bcc
No known key found for this signature in database
2 changed files with 69 additions and 1 deletions
  1. 2
    1
      README.md
  2. 67
    0
      isOdd.cs

+ 2
- 1
README.md View File

@@ -6,4 +6,5 @@ This is a Git repository of elementary algorithm programs for every language I k
6 6
 
7 7
 ## Programming Languages List
8 8
 - C
9
-- C++
9
+- C++
10
+- C#

+ 67
- 0
isOdd.cs View File

@@ -0,0 +1,67 @@
1
+using System;
2
+
3
+/* "Odd number check (now with classes!)
4
+ *
5
+ * Ah, C#. The little child of Microsoft.
6
+ *
7
+ * Honestly, I've never been a fan of C#. Might be because I am used to structural programming in C and can't get out of the habit.
8
+ * Overall, I have used C# for maybe a couple of projects. I have mostly done it because I was too lazy to code a good-looking UI
9
+ * and used Visual Studio for it. Since C# was mostly default and mostly C, I was like "eh".
10
+ *
11
+ * I've since left it to rot in the back of my mind since Java does the OOP part better, and because I actually have the right mentality
12
+ * there when it comes to OOP, compared to C#.
13
+ *
14
+ * This is an over-compartmentalized version of the odd number check. Same as even number check in C++, but with *way* too many objects.
15
+ * I like how clinical I was with this, honestly. Probably more than with the other C# projects I have.
16
+ *
17
+ */
18
+
19
+namespace isOdd
20
+{
21
+    class parityChecker
22
+    {
23
+        public int numberToCheck;
24
+        public bool parity {get; set;}
25
+
26
+        public void setNumber(int x) {
27
+            numberToCheck = x;
28
+        }
29
+
30
+        public int getNumber() {
31
+            return numberToCheck;
32
+        }
33
+
34
+        public bool isOdd() {
35
+            if (numberToCheck % 2 == 1)
36
+            {
37
+                parity = true;
38
+            } else {
39
+                parity = false;
40
+            }
41
+            return parity;
42
+        }
43
+        
44
+        public parityChecker()
45
+        {
46
+            parity = true;
47
+            numberToCheck = 0;
48
+        }
49
+    }
50
+
51
+    class Program
52
+    {
53
+        static void Main(string[] args)
54
+        {
55
+            parityChecker check = new parityChecker();
56
+            Console.WriteLine("Gimme an odd number: ");
57
+            int x = Convert.ToInt32(Console.ReadLine());
58
+            check.setNumber(x);
59
+            if (check.isOdd())
60
+            {
61
+                Console.WriteLine("That's an odd number! Well done!");
62
+            } else {
63
+                Console.WriteLine("You donut, that isn't odd. What are you doing with your life?");
64
+            }
65
+        }
66
+    }
67
+}

Loading…
Cancel
Save