├── .gitignore
├── Course Quizzes and Coding Assignment.docx
├── LICENSE
├── README.md
├── Section 1 -GetStarted
├── Assignment1
│ ├── ACTIVITY - Coding Assignment 1.docx
│ ├── Assignment1.csproj
│ └── Program.cs
├── Assignment1Solution
│ ├── Assignment1Solution.csproj
│ └── Program.cs
└── Basics
│ ├── Basics.csproj
│ └── Program.cs
├── Section 2 -Variables
├── Arrays
│ ├── Arrays.csproj
│ └── Program.cs
├── Assignment1
│ ├── Assignment1.csproj
│ └── Program.cs
├── Assignment1Solution
│ ├── Assignment1Solution.csproj
│ └── Program.cs
├── Boolean
│ ├── Boolean.csproj
│ └── Program.cs
├── Numbers
│ ├── Numbers.csproj
│ └── Program.cs
└── Text
│ ├── Program.cs
│ └── Text.csproj
├── Section 3 -Operators
├── Assignment1
│ ├── Assignment1.csproj
│ └── Program.cs
├── Assignment1Solution
│ ├── Assignment1Solution.csproj
│ └── Program.cs
├── AssignmentOperators
│ ├── AssignmentOperators.csproj
│ └── Program.cs
├── ComparisonOperators
│ ├── ComparisonOperators.csproj
│ └── Program.cs
├── ConditionalOperators
│ ├── ConditionalOperators.csproj
│ └── Program.cs
├── MathematicalOperators
│ ├── MathematicalOperators.csproj
│ └── Program.cs
└── UnaryOperators
│ ├── Program.cs
│ └── UnaryOperators.csproj
├── Section 4 -SelectionStatements
├── Assignment1
│ ├── Assignment1.csproj
│ └── Program.cs
├── Assignment1Solution
│ ├── Assignment1Solution.csproj
│ └── Program.cs
├── Assignment2
│ ├── Assignment2.csproj
│ └── Program.cs
├── Assignment2Solution
│ ├── Assignment2Solution.csproj
│ └── Program.cs
├── Assignment3
│ ├── Assignment3.csproj
│ └── Program.cs
├── Assignment3Solution
│ ├── Assignment3Solution.csproj
│ └── Program.cs
├── Assignment4
│ ├── Assignment4.csproj
│ └── Program.cs
├── Assignment4Solution
│ ├── Assignment4Solution.csproj
│ └── Program.cs
├── IfStatements
│ ├── IfStatements.csproj
│ └── Program.cs
└── SwitchStatements
│ ├── Program.cs
│ └── SwitchStatements.csproj
├── Section 5 -IterativeStatements
├── Assignment1
│ ├── Assignment1.csproj
│ └── Program.cs
├── Assignment1Solution
│ ├── Assignment1Solution.csproj
│ └── Program.cs
├── Assignment2
│ ├── Assignment2.csproj
│ └── Program.cs
├── Assignment2Solution
│ ├── Assignment2Solution.csproj
│ └── Program.cs
├── Assignment3
│ ├── Assignment3.csproj
│ └── Program.cs
├── Assignment3Solution
│ ├── Assignment3Solution.csproj
│ └── Program.cs
├── Foreach
│ ├── Foreach.csproj
│ └── Program.cs
└── Loops
│ ├── Loops.csproj
│ └── Program.cs
└── Section 6 -Debugging
└── Debugging
├── Debugging.csproj
└── Program.cs
/.gitignore:
--------------------------------------------------------------------------------
1 | bin
2 | obj
3 | .vscode
--------------------------------------------------------------------------------
/Course Quizzes and Coding Assignment.docx:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PacktPublishing/C-sharp-Basics-for-Absolute-Beginners-in-C-Sharp-and-dot-NET/7a01fffc58e66b2c9880a0788028f2ee882fb5b5/Course Quizzes and Coding Assignment.docx
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2021 Packt
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | # C# Basics for Absolute Beginners in C# and .NET
5 | A guide to learning the fundamentals of C# .NET programming for beginners in C# for starting a C# .NET career
6 |
7 | ## About the Video Course
8 | This course will teach you the fundamentals of the C# programming language in .NET from the ground up. You will apply the learnings through lots of quizzes, assignments, coding challenges, etc. You will be taken through a carefully selected approach for beginners towards learning C# programming fundamentals.
9 |
10 | If you are completely new to C# programming, you might be feeling entirely lost on where and how to get started to learn C#. You are finding the free C# tutorial videos on the internet too overwhelming or difficult to understand. You feel confused and helpless without proper guidance. You are planning or moved to another project which works on C# programming language.
11 |
12 | You are looking for a direction to learn the fundamentals of C# programming language. You want to understand C# coding concepts through an easier approach. You are looking for a helping hand to learn the basics of C# .NET programming. You are looking for ways to improve your current situation. This course will help you in achieving them.
13 |
14 | You will be mentored throughout each step of your learning process. This course will help you in giving a head start to your new journey as a C# programmer. This course will make you apply the learnings by coding for simple problem statements.
15 |
16 |
17 |
18 | ## Repository for the C# Basics Course
19 | This repo covers the following:
20 | * Demo
21 | * Assignment (ready-made projects to start working)
22 | * Assignment Solutions
23 |
24 |
25 |
--------------------------------------------------------------------------------
/Section 1 -GetStarted/Assignment1/ACTIVITY - Coding Assignment 1.docx:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PacktPublishing/C-sharp-Basics-for-Absolute-Beginners-in-C-Sharp-and-dot-NET/7a01fffc58e66b2c9880a0788028f2ee882fb5b5/Section 1 -GetStarted/Assignment1/ACTIVITY - Coding Assignment 1.docx
--------------------------------------------------------------------------------
/Section 1 -GetStarted/Assignment1/Assignment1.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Exe
5 | netcoreapp3.1
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/Section 1 -GetStarted/Assignment1/Program.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace Assignment1
4 | {
5 | class Program
6 | {
7 | static void Main(string[] args)
8 | {
9 | // Exercise 1
10 | Comment this line using single line comment.
11 |
12 | // Exercise 2
13 | Comment this and the next line using multiline comment.
14 | Visual Studio will show error if we dont comment normal text.
15 |
16 | // Exercise 3
17 | // Write a C# statement to print your name to the console.
18 |
19 | }
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/Section 1 -GetStarted/Assignment1Solution/Assignment1Solution.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Exe
5 | netcoreapp3.1
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/Section 1 -GetStarted/Assignment1Solution/Program.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace Assignment1Solution
4 | {
5 | class Program
6 | {
7 | static void Main(string[] args)
8 | {
9 | // Exercise 1
10 | // Comment this line using single line comment.
11 |
12 | // Exercise 2
13 | // Comment this and the next line using multiline comment.
14 | // Visual Studio will show error if we dont comment normal text.
15 |
16 | // Exercise 3
17 | // Write a C# statement to print your name to the console.
18 | Console.WriteLine("Praveenkumar Bouna");
19 | }
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/Section 1 -GetStarted/Basics/Basics.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Exe
5 | netcoreapp3.1
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/Section 1 -GetStarted/Basics/Program.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace Basics
4 | {
5 | class Program
6 | {
7 | ///
8 | /// Basics of the C# language.
9 | ///
10 | static void Main(string[] args)
11 | {
12 | // C# Statements
13 | // Single instruction of code
14 | // Similar to English.
15 | // Ends with ;
16 | Console.WriteLine("Hello");
17 |
18 | // C# Blocks
19 | // Group of statements
20 | // Starts with { and ends with }
21 | if(true)
22 | {
23 | /* Checking if statement
24 | with some sample declarations
25 | End of multiline statements
26 | */
27 | int a = 100;
28 | int b = a;
29 | }
30 |
31 | // C# Comments
32 | // 3 types of comments
33 | // Single line comment //
34 | // Multiline comment /* */
35 | // Documentation comment ///
36 |
37 | // C# Read and Write
38 | string str = Console.ReadLine();
39 | Console.WriteLine("Hello, World");
40 | Console.Write("hello");
41 | Console.WriteLine(str);
42 | }
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/Section 2 -Variables/Arrays/Arrays.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Exe
5 | netcoreapp3.1
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/Section 2 -Variables/Arrays/Program.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace Arrays
4 | {
5 | class Program
6 | {
7 | static void Main(string[] args)
8 | {
9 | string sun = "sunday";
10 | string mon = "monday";
11 |
12 | string[] days = new string[]
13 | {
14 | "Sunday",
15 | "Monday",
16 | "Tuesday",
17 | "Wedneday",
18 | "Thursday",
19 | "Friday",
20 | "Saturday"
21 | };
22 |
23 | Console.WriteLine(days[0]);
24 | Console.WriteLine(days[1]);
25 | Console.WriteLine(days[2]);
26 |
27 | string[] daysNew;
28 | daysNew = new string[7];
29 | daysNew[0] = "Sunday";
30 | daysNew[1] = "Monday";
31 | daysNew[2] = "Tuesday";
32 | Console.Write(daysNew[0]);
33 | Console.Write(daysNew[1]);
34 | Console.Write(daysNew[2]);
35 |
36 | int length = daysNew.Length;
37 | Console.WriteLine(length);
38 | }
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/Section 2 -Variables/Assignment1/Assignment1.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Exe
5 | netcoreapp3.1
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/Section 2 -Variables/Assignment1/Program.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace Assignment1
4 | {
5 | class Program
6 | {
7 | static void Main(string[] args)
8 | {
9 | // Exercise 1
10 | // Write C# code snippet to declare a character and assign value 'C'.
11 | // Print the same to the Console.
12 |
13 |
14 |
15 | // Exercise 2
16 | // Write C# code snippet to read a name as string from console
17 | // and print "Hello, " along with the name to the Console.
18 |
19 |
20 |
21 | // Exercise 3
22 | // Rewrite the solution of Exercise 2 to use string interpolation ('$')
23 | // to combine two strings instead of using the '+' symbol.
24 |
25 |
26 |
27 | }
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/Section 2 -Variables/Assignment1Solution/Assignment1Solution.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Exe
5 | netcoreapp3.1
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/Section 2 -Variables/Assignment1Solution/Program.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace Assignment1Solution
4 | {
5 | class Program
6 | {
7 | static void Main(string[] args)
8 | {
9 | // Exercise 1
10 | // Write C# code snippet to declare a character and assign value 'C'.
11 | // Print the same to the Console.
12 | char ch;
13 | ch = 'C';
14 | Console.WriteLine(ch);
15 |
16 | // Exercise 2
17 | // Write C# code snippet to read a name as string from console
18 | // and print "Hello, " along with the name to the Console.
19 | string str;
20 | Console.WriteLine("Enter your name: ");
21 | str = Console.ReadLine();
22 | Console.WriteLine("Hello, " + str);
23 |
24 | // Exercise 3
25 | // Rewrite the solution of Exercise 2 to use string interpolation ('$')
26 | // to combine two strings instead of using the '+' symbol.
27 | string str2;
28 | Console.Write("Enter your name: ");
29 | str2 = Console.ReadLine();
30 | Console.WriteLine($"Hello, {str2}");
31 | }
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/Section 2 -Variables/Boolean/Boolean.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Exe
5 | netcoreapp3.1
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/Section 2 -Variables/Boolean/Program.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace Boolean
4 | {
5 | class Program
6 | {
7 | static void Main(string[] args)
8 | {
9 | bool b;
10 | b = true;
11 |
12 | Console.WriteLine("Before assignment");
13 | Console.WriteLine(b);
14 |
15 | b = bool.Parse(Console.ReadLine());
16 | Console.WriteLine("After assignment");
17 | Console.WriteLine(b);
18 | }
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/Section 2 -Variables/Numbers/Numbers.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Exe
5 | netcoreapp3.1
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/Section 2 -Variables/Numbers/Program.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace Numbers
4 | {
5 | class Program
6 | {
7 | static void Main(string[] args)
8 | {
9 | // Whole numbers
10 | int i = 10;
11 | Console.WriteLine(i);
12 | int j = int.Parse(Console.ReadLine());
13 | Console.WriteLine(j);
14 |
15 | short s = 100;
16 | long l = 10000L;
17 | uint ui = 12;
18 |
19 | int intNum = (int)l;
20 | short shortNum = (short)i;
21 |
22 | // Decimal numbers
23 | float f = 10.5f;
24 | double d = 123.99;
25 | decimal dd = 345.80m;
26 |
27 | float floatNew = (float)dd;
28 | decimal decimalNew = (decimal)f;
29 | decimal decimalNew2 = (decimal)d;
30 | }
31 | }
32 | }
33 |
34 |
--------------------------------------------------------------------------------
/Section 2 -Variables/Text/Program.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace Text
4 | {
5 | class Program
6 | {
7 | static void Main(string[] args)
8 | {
9 | // C# Characters
10 | char c = 'a';
11 | char d = '1';
12 | char s = '*';
13 |
14 | int i = sizeof(char); // i = 2
15 |
16 | // C# Strings
17 | string s1 = "hello";
18 | string s2 = "12345";
19 | string s3 = "***";
20 |
21 | Console.WriteLine("hello, world");
22 | Console.WriteLine(s1);
23 | Console.WriteLine(s2);
24 | Console.WriteLine(s3);
25 |
26 | // Different ways to represent strings
27 | // Literals
28 | string str1 = "world";
29 | // Verbatim
30 | string str2 = @"c:\myfolder\test.txt";
31 | // Interpolated
32 | string str3 = $"hello {str1}"; // hello world
33 |
34 | Console.WriteLine(str1);
35 | Console.WriteLine(str2);
36 | Console.WriteLine(str3);
37 |
38 |
39 |
40 | }
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/Section 2 -Variables/Text/Text.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Exe
5 | netcoreapp3.1
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/Section 3 -Operators/Assignment1/Assignment1.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Exe
5 | netcoreapp3.1
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/Section 3 -Operators/Assignment1/Program.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace Assignment1
4 | {
5 | class Program
6 | {
7 | static void Main(string[] args)
8 | {
9 | // Write a C# program to calculate (a-b)^2 by reading the values of a and b from the console.
10 | // For eg.,
11 | // (5-3)^2 = 4
12 | // (10-6)^2 = 16
13 | // Note: The formula of (a-b)^2 = (a x a) + (b x b) - (2 x a x b)
14 |
15 | // TODO.
16 | }
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/Section 3 -Operators/Assignment1Solution/Assignment1Solution.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Exe
5 | netcoreapp3.1
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/Section 3 -Operators/Assignment1Solution/Program.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace Assignment1Solution
4 | {
5 | class Program
6 | {
7 | static void Main(string[] args)
8 | {
9 | // Write a C# program to calculate (a-b)^2 by reading the values of a and b from the console.
10 | // For eg.,
11 | // (5-3)^2 = 4
12 | // (10-6)^2 = 16
13 | // Note: The formula of (a-b)^2 = (a x a) + (b x b) - (2 x a x b)
14 |
15 | // Read the two numbers and assign to a and b.
16 | Console.WriteLine("Enter the first number: ");
17 | int a = int.Parse(Console.ReadLine());
18 | Console.WriteLine("Enter the second number: ");
19 | int b = int.Parse(Console.ReadLine());
20 |
21 | // Do the calculation as per formula
22 | int result = (a*a) + (b*b) - (2*a*b);
23 | Console.WriteLine($"Result: {result}");
24 | }
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/Section 3 -Operators/AssignmentOperators/AssignmentOperators.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Exe
5 | netcoreapp3.1
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/Section 3 -Operators/AssignmentOperators/Program.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace AssignmentOperators
4 | {
5 | class Program
6 | {
7 | static void Main(string[] args)
8 | {
9 | // C# Assignment Operators
10 |
11 | int a;
12 |
13 | a = 10;
14 |
15 | a += 5;
16 | Console.WriteLine($"a += 5 : {a}");
17 |
18 | a -= 5;
19 | Console.WriteLine($"a -= 5 : {a}");
20 |
21 | a *= 5;
22 | Console.WriteLine($"a *= 5 : {a}");
23 |
24 | a /= 5;
25 | Console.WriteLine($"a /= 5 : {a}");
26 | }
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/Section 3 -Operators/ComparisonOperators/ComparisonOperators.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Exe
5 | netcoreapp3.1
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/Section 3 -Operators/ComparisonOperators/Program.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace ComparisonOperators
4 | {
5 | class Program
6 | {
7 | static void Main(string[] args)
8 | {
9 | // C# Comparison Operators
10 |
11 | int a = 60;
12 |
13 | Console.WriteLine($"a : {a}");
14 |
15 | Console.WriteLine($"a == 50 : {a == 50}");
16 | Console.WriteLine($"a != 50 : {a != 50}");
17 | Console.WriteLine($"a > 50 : {a > 50}");
18 | Console.WriteLine($"a < 50 : {a < 50}");
19 |
20 | }
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/Section 3 -Operators/ConditionalOperators/ConditionalOperators.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Exe
5 | netcoreapp3.1
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/Section 3 -Operators/ConditionalOperators/Program.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace ConditionalOperators
4 | {
5 | class Program
6 | {
7 | static void Main(string[] args)
8 | {
9 | // C# Conditional Operators
10 |
11 | bool a = false;
12 | bool b = true;
13 |
14 | Console.WriteLine($"a b : {a} {b}");
15 | Console.WriteLine($"a && b : {a && b}");
16 | Console.WriteLine($"a || b : {a || b}");
17 |
18 | a = true;
19 | b = true;
20 | Console.WriteLine($"a b : {a} {b}");
21 | Console.WriteLine($"a && b : {a && b}");
22 | Console.WriteLine($"a || b : {a || b}");
23 |
24 | a = false;
25 | b = false;
26 | Console.WriteLine($"a b : {a} {b}");
27 | Console.WriteLine($"a && b : {a && b}");
28 | Console.WriteLine($"a || b : {a || b}");
29 |
30 | }
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/Section 3 -Operators/MathematicalOperators/MathematicalOperators.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Exe
5 | netcoreapp3.1
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/Section 3 -Operators/MathematicalOperators/Program.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace MathematicalOperators
4 | {
5 | class Program
6 | {
7 | static void Main(string[] args)
8 | {
9 | // C# Mathematical Operators.
10 |
11 | int a = 10, b = 3;
12 | Console.WriteLine($"a + b = {a+b}");
13 | Console.WriteLine($"a - b = {a-b}");
14 | Console.WriteLine($"a * b = {a*b}");
15 | Console.WriteLine($"a / b = {a/b}");
16 |
17 | float f = 11.0f;
18 | Console.WriteLine($"f / b = {f/b}");
19 |
20 | Console.WriteLine($"a % b = {a%b}");
21 | }
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/Section 3 -Operators/UnaryOperators/Program.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace UnaryOperators
4 | {
5 | class Program
6 | {
7 | static void Main(string[] args)
8 | {
9 | // C# Unary operators.
10 |
11 | int a, b;
12 |
13 | a = 10;
14 | b = ++a;
15 | Console.WriteLine($"Prefix ++ , a = {a}, b = {b}");
16 |
17 | a = 10;
18 | b = a++;
19 | Console.WriteLine($"Postfix ++ , a = {a}, b = {b}");
20 |
21 | a = 10;
22 | b = --a;
23 | Console.WriteLine($"Prefix -- , a = {a}, b = {b}");
24 |
25 | a = 10;
26 | b = a--;
27 | Console.WriteLine($"Postfix -- , a = {a}, b = {b}");
28 | }
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/Section 3 -Operators/UnaryOperators/UnaryOperators.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Exe
5 | netcoreapp3.1
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/Section 4 -SelectionStatements/Assignment1/Assignment1.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Exe
5 | netcoreapp3.1
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/Section 4 -SelectionStatements/Assignment1/Program.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace Assignment1
4 | {
5 | class Program
6 | {
7 | static void Main(string[] args)
8 | {
9 | // Write C# code snippet to read an integer and print it if it is divisble by 3.
10 | // Note that you can use int.Parse(string) function to convert a string to integer.
11 |
12 | // TODO.
13 | }
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/Section 4 -SelectionStatements/Assignment1Solution/Assignment1Solution.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Exe
5 | netcoreapp3.1
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/Section 4 -SelectionStatements/Assignment1Solution/Program.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace Assignment1Solution
4 | {
5 | class Program
6 | {
7 | static void Main(string[] args)
8 | {
9 | // Write C# code snippet to read an integer and print it if it is divisble by 3.
10 | // Note that you can use int.Parse(string) function to convert a string to integer.
11 |
12 | // Read the input from the console
13 | string input = Console.ReadLine();
14 |
15 | // Parse to convert the input string to integer
16 | int a = int.Parse(input);
17 |
18 | // Check for divisible by 3
19 | if(a % 3 == 0)
20 | {
21 | Console.WriteLine("The entered number is divisible by 3");
22 | }
23 | else
24 | {
25 | Console.WriteLine("The entered number is NOT divisible by 3");
26 | }
27 |
28 | }
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/Section 4 -SelectionStatements/Assignment2/Assignment2.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Exe
5 | netcoreapp3.1
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/Section 4 -SelectionStatements/Assignment2/Program.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace Assignment2
4 | {
5 | class Program
6 | {
7 | static void Main(string[] args)
8 | {
9 | // Assume a variable phonePrice of type integer holding the price of a phone in dollars.
10 | // Write a sequence of C# selection statements to print “budget” or “mid-range” or “high end” based on the
11 | // price range of the phone - less than 300, between 300 and 800, and more than 800 - respectively
12 |
13 | // TODO.
14 | }
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/Section 4 -SelectionStatements/Assignment2Solution/Assignment2Solution.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Exe
5 | netcoreapp3.1
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/Section 4 -SelectionStatements/Assignment2Solution/Program.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace Assignment2Solution
4 | {
5 | class Program
6 | {
7 | static void Main(string[] args)
8 | {
9 | // Assume a variable phonePrice of type integer for holding the price of a phone in dollars.
10 | // Write a sequence of C# selection statements to print “budget” or “mid-range” or “high end” based on the
11 | // price range of the phone - less than 300, between 300 and 800, and more than 800 - respectively
12 |
13 | decimal phonePrice;
14 |
15 | string input = Console.ReadLine();
16 | phonePrice = decimal.Parse(input);
17 |
18 | // Note: Compiler infers decimal suffic m or M from variable type phonePrice
19 | if(phonePrice < 300)
20 | {
21 | Console.WriteLine("budget");
22 | }
23 | // Note: M for decimal can be appended
24 | else if(phonePrice >= 300M && phonePrice <= 800M)
25 | {
26 | Console.WriteLine("mid-range");
27 | }
28 | // Note: m for decimal can be in lower case as well
29 | else if(phonePrice > 800m)
30 | {
31 | Console.WriteLine("high end");
32 | }
33 | }
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/Section 4 -SelectionStatements/Assignment3/Assignment3.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Exe
5 | netcoreapp3.1
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/Section 4 -SelectionStatements/Assignment3/Program.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace Assignment3
4 | {
5 | class Program
6 | {
7 | static void Main(string[] args)
8 | {
9 | // Write C# code snippet to check whether a entered password is valid or not as per below rules:
10 | // - Password length between 8 and 14 (both inclusive)
11 | // - At least 1 upper case letter
12 | // - At least 1 lower case letter
13 | // - At least 1 numeric letter.
14 | // For eg.,
15 | // Password123 --> Valid
16 | // hello9090 --> Invalid
17 |
18 | // TODO.
19 | }
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/Section 4 -SelectionStatements/Assignment3Solution/Assignment3Solution.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Exe
5 | netcoreapp3.1
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/Section 4 -SelectionStatements/Assignment3Solution/Program.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace Assignment3Solution
4 | {
5 | class Program
6 | {
7 | static void Main(string[] args)
8 | {
9 | // Write C# code snippet to check whether a entered password is valid or not as per below rules:
10 | // - Password length between 8 and 14 (both inclusive)
11 | // - At least 1 upper case letter
12 | // - At least 1 lower case letter
13 | // - At least 1 numeric letter.
14 | // For eg.,
15 | // Password123 --> Valid
16 | // hello9090 --> Invalid
17 |
18 | // These boolean variables will hold the result of each check
19 | bool isLengthValid = false;
20 | bool isUppercase = false;
21 | bool isLowercase = false;
22 | bool isNumeric = false;
23 |
24 | // Read the password as plain text
25 | string password = Console.ReadLine();
26 |
27 | // Check for password length
28 | if(password.Length >= 8 && password.Length <= 14)
29 | {
30 | isLengthValid = true;
31 | }
32 |
33 | // Iterate through each character of the string
34 | for (int i = 0; i < password.Length; i++)
35 | {
36 | char ch = password[i];
37 |
38 | // Check for lower case
39 | if (char.IsLower(ch))
40 | {
41 | isLowercase = true;
42 | }
43 | // Check for upper case
44 | if (char.IsUpper(ch))
45 | {
46 | isUppercase = true;
47 | }
48 | // Check for numeric
49 | if (char.IsNumber(ch))
50 | {
51 | isNumeric = true;
52 | }
53 | }
54 |
55 | // Check whether the password satisfies all conditions
56 | if(isLengthValid && isUppercase && isLowercase && isNumeric)
57 | {
58 | Console.WriteLine("Password is valid");
59 | }
60 | else
61 | {
62 | Console.WriteLine("Password is invalid");
63 | }
64 | }
65 | }
66 | }
67 |
--------------------------------------------------------------------------------
/Section 4 -SelectionStatements/Assignment4/Assignment4.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Exe
5 | netcoreapp3.1
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/Section 4 -SelectionStatements/Assignment4/Program.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace Assignment4
4 | {
5 | class Program
6 | {
7 | static void Main(string[] args)
8 | {
9 | // Write a simple C# calculator program to do basic mathematical operation (+, -, *, /)
10 | // by reading the type of operation and two values. Use switch statements to check
11 | // the type of operation entered and print the result to the console.
12 |
13 | // TODO.
14 | }
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/Section 4 -SelectionStatements/Assignment4Solution/Assignment4Solution.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Exe
5 | netcoreapp3.1
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/Section 4 -SelectionStatements/Assignment4Solution/Program.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace Assignment4Solution
4 | {
5 | class Program
6 | {
7 | static void Main(string[] args)
8 | {
9 | // Write a simple C# calculator program to do basic mathematical operation (+, -, *, /)
10 | // by reading the type of operation and two values. Use switch statements to check
11 | // the type of operation entered and print the result to the console.
12 |
13 | // Display the instructions.
14 | Console.WriteLine("Enter your choice:");
15 | Console.WriteLine("1. Add");
16 | Console.WriteLine("2. Subtract");
17 | Console.WriteLine("3. Multiply");
18 | Console.WriteLine("4. Divide");
19 |
20 | // Read the choice of operation.
21 | int choice = int.Parse(Console.ReadLine());
22 |
23 | // Read the two numbers and assign to a and b.
24 | Console.WriteLine("Enter the first number: ");
25 | int a = int.Parse(Console.ReadLine());
26 | Console.WriteLine("Enter the second number: ");
27 | int b = int.Parse(Console.ReadLine());
28 |
29 | // The variable type used is decimal to hold fractional values in case of division.
30 | decimal result = 0;
31 |
32 | // Switch selection statement on the choice entered.
33 | switch (choice)
34 | {
35 | case 1:
36 | result = a + b;
37 | Console.WriteLine($"Add : {result}");
38 | break;
39 | case 2:
40 | result = a - b;
41 | Console.WriteLine($"Subtract : {result}");
42 | break;
43 | case 3:
44 | result = a * b;
45 | Console.WriteLine($"Multiply : {result}");
46 | break;
47 | case 4:
48 | // Need to convert first variable to decimal, otherwise the fractional part will be lost in case of int variables.
49 | result = (decimal)a / b;
50 | Console.WriteLine($"Divide : {result}");
51 | break;
52 | default:
53 | // Fallback option. Gets executed when user enters inputs other than expected.
54 | Console.WriteLine("Invalid input");
55 | break;
56 | }
57 | }
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/Section 4 -SelectionStatements/IfStatements/IfStatements.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Exe
5 | netcoreapp3.1
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/Section 4 -SelectionStatements/IfStatements/Program.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace IfStatements
4 | {
5 | class Program
6 | {
7 | static void Main(string[] args)
8 | {
9 | // Write a C# program to get favourite subject option from user and print the subject name to the console.
10 |
11 | char ch;
12 |
13 | Console.WriteLine("Enter your favourite subject option: ");
14 | ch = (char)Console.Read();
15 |
16 | if(ch == 'e')
17 | {
18 | Console.WriteLine("Favourite subject is English");
19 | }
20 | else if(ch == 'm')
21 | {
22 | Console.WriteLine("Favourite subject is Maths");
23 | }
24 | else if(ch == 's')
25 | {
26 | Console.WriteLine("Favourite subject is Science");
27 | }
28 | else
29 | {
30 | Console.WriteLine("Other options than my favourite!");
31 | }
32 |
33 | Console.WriteLine("End of the program");
34 | }
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/Section 4 -SelectionStatements/SwitchStatements/Program.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace SwitchStatements
4 | {
5 | class Program
6 | {
7 | static void Main(string[] args)
8 | {
9 | // Write a C# program to get favourite subject option from user and print the subject name to the console.
10 |
11 | char ch;
12 |
13 | Console.WriteLine("Enter your favourite subject option: ");
14 | ch = (char)Console.Read();
15 |
16 | switch(ch)
17 | {
18 | case 'e':
19 | {
20 | Console.WriteLine("Favourite subject is English");
21 | break;
22 | }
23 | case 'm':
24 | {
25 | Console.WriteLine("Favourite subject is Maths");
26 | break;
27 | }
28 | case 's':
29 | {
30 | Console.WriteLine("Favourite subject is Science");
31 | break;
32 | }
33 | default:
34 | {
35 | Console.WriteLine("Other than favourites!");
36 | break;
37 | }
38 | }
39 | }
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/Section 4 -SelectionStatements/SwitchStatements/SwitchStatements.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Exe
5 | netcoreapp3.1
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/Section 5 -IterativeStatements/Assignment1/Assignment1.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Exe
5 | netcoreapp3.1
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/Section 5 -IterativeStatements/Assignment1/Program.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace Assignment1
4 | {
5 | class Program
6 | {
7 | static void Main(string[] args)
8 | {
9 | // Write C# code snippet read a positive number from the console and print the total number of digits in it.
10 | // For eg., 135 --> 3, 90 --> 2, 98788 --> 5
11 | // Note that you can use int.Parse(string) function to convert a string to integer.
12 |
13 | // TODO.
14 | }
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/Section 5 -IterativeStatements/Assignment1Solution/Assignment1Solution.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Exe
5 | netcoreapp3.1
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/Section 5 -IterativeStatements/Assignment1Solution/Program.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace Assignment1Solution
4 | {
5 | class Program
6 | {
7 | static void Main(string[] args)
8 | {
9 | // Write C# code snippet read a positive number from the console and print the total number of digits in it.
10 | // For eg., 135 --> 3, 90 --> 2, 98788 --> 5
11 | // Note that you can use int.Parse(string) function to convert a string to integer.
12 |
13 | // Declare the variables
14 | int i = 0;
15 | int count = 0;
16 |
17 | // Read the input and store in a variable 'i'
18 | string input = Console.ReadLine();
19 | i = int.Parse(input);
20 |
21 | // Loop through each time dividing by 10 to count the digits.
22 | do
23 | {
24 | count++;
25 | i = i / 10;
26 | }while (i > 0);
27 |
28 | // Print to the console output
29 | Console.WriteLine(count);
30 | }
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/Section 5 -IterativeStatements/Assignment2/Assignment2.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Exe
5 | netcoreapp3.1
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/Section 5 -IterativeStatements/Assignment2/Program.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace Assignment2
4 | {
5 | class Program
6 | {
7 | static void Main(string[] args)
8 | {
9 | // Write C# code snippet to read a positive integer from the console and print it's factorial value.
10 | // Factorial of a number refers to product of all numbers below it.
11 | // For eg.,
12 | // factorial(3) = 3 * 2 * 1 = 6
13 | // factorial(5) = 5 * 4 * 3 * 2 * 1 = 120
14 |
15 | // TODO
16 | }
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/Section 5 -IterativeStatements/Assignment2Solution/Assignment2Solution.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Exe
5 | netcoreapp3.1
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/Section 5 -IterativeStatements/Assignment2Solution/Program.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace Assignment2Solution
4 | {
5 | class Program
6 | {
7 | static void Main(string[] args)
8 | {
9 | // Write C# code snippet to read a positive integer from the console and print it's factorial value.
10 | // Factorial of a number refers to product of all numbers below it.
11 | // For eg.,
12 | // factorial(3) = 3 * 2 * 1 = 6
13 | // factorial(5) = 5 * 4 * 3 * 2 * 1 = 120
14 |
15 | // Variable declarations
16 | int a;
17 | int result = 1;
18 |
19 | // Read the input and store in a variable 'a'
20 | string s = Console.ReadLine();
21 | a = int.Parse(s);
22 |
23 | while (a > 0)
24 | {
25 | result = result * a;
26 | a--;
27 | }
28 |
29 | // Print the result to the console output
30 | Console.WriteLine(result);
31 | }
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/Section 5 -IterativeStatements/Assignment3/Assignment3.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Exe
5 | netcoreapp3.1
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/Section 5 -IterativeStatements/Assignment3/Program.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace Assignment3
4 | {
5 | class Program
6 | {
7 | static void Main(string[] args)
8 | {
9 | // Write C# code snippet to print only the numbers from an array containing both integer and string values.
10 | // For eg.,
11 | // { "2", "Red", "67" } --> 2, 67
12 | // { "Hello", "45", "12", "Rose" } --> 45, 12
13 |
14 | // TODO.
15 | }
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/Section 5 -IterativeStatements/Assignment3Solution/Assignment3Solution.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Exe
5 | netcoreapp3.1
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/Section 5 -IterativeStatements/Assignment3Solution/Program.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace Assignment3Solution
4 | {
5 | class Program
6 | {
7 | static void Main(string[] args)
8 | {
9 | // Write C# code snippet to print only the numbers from an array containing both integer and string values.
10 | // For eg.,
11 | // { "2", "Red", "67" } --> 2, 67
12 | // { "Hello", "45", "12", "Rose" } --> 45, 12
13 |
14 | // Array declaration
15 | string[] array = new string[] {"2", "Red", "67"};
16 |
17 | int value;
18 |
19 | // Iterate through each array element and check for numeric value
20 | for (int j = 0; j < array.Length; j++)
21 | {
22 | if (int.TryParse(array[j], out value))
23 | {
24 | // Found numeric value! Print it to the console output.
25 | Console.WriteLine(value);
26 | }
27 | }
28 | }
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/Section 5 -IterativeStatements/Foreach/Foreach.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Exe
5 | netcoreapp3.1
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/Section 5 -IterativeStatements/Foreach/Program.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace Foreach
4 | {
5 | class Program
6 | {
7 | static void Main(string[] args)
8 | {
9 | // Foreach statement demo
10 |
11 | string[] days = new string[]
12 | {
13 | "Sunday",
14 | "Monday",
15 | "Tuesday",
16 | "Wednesday",
17 | "Thursday",
18 | "Friday",
19 | "Saturday"
20 | };
21 |
22 | foreach(string s in days)
23 | {
24 | Console.WriteLine(s);
25 | }
26 |
27 | Console.WriteLine("End of the program");
28 | }
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/Section 5 -IterativeStatements/Loops/Loops.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Exe
5 | netcoreapp3.1
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/Section 5 -IterativeStatements/Loops/Program.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace Loops
4 | {
5 | class Program
6 | {
7 | static void Main(string[] args)
8 | {
9 | int input;
10 |
11 | Console.WriteLine("Enter a number: ");
12 | input = int.Parse(Console.ReadLine());
13 |
14 | // While loop
15 | Console.WriteLine("While Loop");
16 | int i = 0;
17 | while (i < input && i < 5)
18 | {
19 | Console.WriteLine(i);
20 | i++;
21 | }
22 |
23 | // Do While loop
24 | i = 0;
25 | Console.WriteLine("Do While Loop");
26 | do
27 | {
28 | Console.WriteLine(i);
29 | i++;
30 | }while(i < input && i < 5);
31 |
32 | // For loop
33 | Console.WriteLine("For Loop");
34 | for(int j = 0; j < input && j < 5; j++)
35 | {
36 | Console.WriteLine(j);
37 | }
38 | Console.WriteLine("End of the program!");
39 | }
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/Section 6 -Debugging/Debugging/Debugging.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Exe
5 | netcoreapp3.1
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/Section 6 -Debugging/Debugging/Program.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace Debugging
4 | {
5 | class Program
6 | {
7 | static void Main(string[] args)
8 | {
9 | // Debugging
10 | // - Process of locating bugs/issues and removing them using debugging tools.
11 | // - Usually it takes more time to debug than coding!
12 | // - Debugging is a part of every programmers day-to-day life.
13 |
14 | // Print all even numbers below 10
15 | PrintEvenNumbers();
16 | }
17 |
18 | static void PrintEvenNumbers()
19 | {
20 | int input = 10;
21 | int i = 1;
22 |
23 | while (i < input)
24 | {
25 | bool result = ((i / 2) == 0);
26 | if(!result)
27 | {
28 | // Found an even number.
29 | // Print it.
30 | Console.WriteLine(i);
31 | }
32 | i++;
33 | }
34 | }
35 | }
36 | }
37 |
--------------------------------------------------------------------------------