Sunday, April 23, 2023

Complete C# Master Class note 1

 

1. C# variables defined in class level can be accessed by the method directly (without static keyword). Only if the variables are defined with static keyword, then they are shared by all instances. Variables defined within the method can only be used in the method.

2. decimal is used mostly in financial applications.

3. Value types hold the value directly on its own memory space. The value type uses a heap to store the value. Reference types store the memory location of the data, like string, class, array.

4.

// See https://aka.ms/new-console-template for more information

Console.ForegroundColor = ConsoleColor.DarkYellow;

Console.WriteLine("Hello, World!");

string? value = Console.ReadLine();

Console.WriteLine("You input {0}",value);

int n = Int32.Parse("32");//or int.Parse

Console.WriteLine(n);

Console.WriteLine($"Hello the value is {value}");

const double MYPI = Math.PI;

Console.WriteLine(MYPI);


string numberAsString = "128SDF";

int parsedValue;

bool success = int.TryParse(numberAsString, out parsedValue);

Console.WriteLine(success);

5.

destructor: ~Member()     Debug.write();

6.

By using the params keyword, you can specify a method parameter that takes a variable number of arguments. The parameter type must be a single-dimensional array.

7.

List<T> is a generic class. It supports storing values of a specific type without casting to or from object (which would have incurred boxing/unboxing overhead when T is a value type in the ArrayList case). ArrayList simply stores object references.

8.

Hashtable

foreach(DictionaryEntry entry in studentsHashTable){}

or

foreach(Student value in studentsHashTable.values){}


9. Dictionary implementation is actually based on Hashtable but it's generic and preferred.

10.

VS offers 2 automatic-watch tool windows: The Locals and Autos windows.

The Locals will show local variables of the current scope. It usually starts with this, which represents the current class.

The Autos window will show all variables used in the current line and in the previous line. These could be local variables, class members or static variables. The Autos also shows values returned from methods, which is useful at times.


No comments:

Post a Comment