An Intro to C#
NOTE: Everything is written in simple and short words — like a student's notes. Declaring variables of different types: // type variablename = value; int num; string s; bool b; char ch; double dub; float fl; decimal dc; // arrays are of fixed length and can be provided a size during initialisation. // Compiler infers the size if you do not provide it. int[] arr; List<int> nums; // List<type> varname Dictionary<string, int> dict; // Dictionary<keyType, valueType> varname; Initialising variables of different types. // Syntax: // Either `var varname = value;` — here type is inferred by the compiler // Or `type varname = value;` var num1 = 1; int num2 = 2; var dub1 = 1.99; double dub2 = 2.99; var fl1 = 1.99f; // for float 'f' or 'F' suffix must be provided at the end of the value. float fl2 = 2.99f; var dc1 = 1.99m; decimal dc2 = 2.99m; // for decimal 'm' or 'M' suffix must be provided at the end of the value. var ch1 = 'A'; char ch2 = 'B'; var s1 = "first one"; string s2 = "second one"; var b1 = true; bool b2 = false; // Ways to Initialise an array: // NOTE: Some of the other ways to initialise an array, a list, and a dictionary have not been added here. // Only standard and recommended ways have been added. // recommended way for legacy projects int[] arr1 = { 1, 2, 3 }; // creates an array with values {1, 2, 3} // recommended for new projects int[] arr2 = [1, 2, 3]; // use square brackets; creates an array with values [1, 2, 3]. // Ways to initialise a list: List<int> nums1 = [1, 2, 3]; // modern syntax: c# 12+ // traditional standard: using var keyword var nums2 = new List<int>() { 1, 2, 3 }; // Ways to initialise a dictionary: // classic way: var dict1 = new Dictionary<string, int> { {"user1", 1}, }; // Recommended way: var dict2 = new Dictionary<string, int> { ["user1"] = 1, }; Constants // const type varname = value; const int num = 5; OOP In short words, Object-oriented programming (OOP) is a way of designing software around data, or objects, rather than functions and logic. ...