Tuesday, 13 August 2019

Dus: DUS BAHANE KER KE LE GAYA DIL



DUS:

Boolean data type is replaced by checkbox in the grids. Example:
<DataGridCheckBoxColumn Header="Consent?" Binding="{Binding ConsentFlag}" />

No: Directory Management in C#




Nine:

If the target directory has any subdirectory(ies) in it then Directory.Delete() will throw an exception that "Directory is not empty".

Fix:

1. Traverse from the bottom to top of the target directory path.

2. In order to Traverse, we need to construct the absolute path of the target directory and its subdirectories.

3. Once we have the absolute path, we can enumerate the directories and perform Deletion one by one.

AATH: AUto Generataion



  1. DataTable dt = new DataTable();
  2. dt.Columns.Add("Column1", typeof(String)); // First col is a string
  3. dt.Columns.Add("Column2", typeof(Boolean)); // Second col is a boolean
  4. DataRow dr = dt.NewRow();
  5. dr["Column1"] = "Data";
  6. dr["Column2"] = true;
  7. dt.Rows.Add(dr);
  8. dataGridView1.DataSource = dt;



AATH:

The AutoGenerateColumns property of DataGrid should set to [AutoGenerateColumns="false"] when creating the dataGrid and customized columns should be define as per the requirement.

SAAT: Data Grid and Data Island


Operator overloadability

The null-coalescing operator cannot be overloaded.

C# language specification

For more information, see The null coalescing operator section of the C# language specification.


SAAT:

Data Binding in WPF used to connect the flow of data between UI and the code. Binding can be performed in two different ways:
1. Data Island - creating data in the immediate window
2. The data source is used to retrieve data and then use in the window.

Class is required in both cases that contains the definition of data.

Cheh: Data Binding in C#

  • In expressions with the null-conditional operators ?. and ?[], you can use the null-coalescing operator to provide an alternative expression to evaluate in case the result of the expression with null-conditional operations is null:
    C#
    double SumNumbers(List<double[]> setsOfNumbers, int indexOfSetToSum)
    {
        return setsOfNumbers?[indexOfSetToSum]?.Sum() ?? double.NaN;
    }
    
    var sum = SumNumbers(null, 0);
    Console.WriteLine(sum);  // output: NaN
CHEH:

LIFO(Last in First Out): Stack Collection we will use.

Paanch: Collections in C#



The null-coalescing operator ?? returns the value of its left-hand operand if it isn't null; otherwise, it evaluates the right-hand operand and returns its result. The ?? operator doesn't evaluate its right-hand operand if the left-hand operand evaluates to non-null.
The null-coalescing operator is right-associative, that is, an expression of the form
C#
a ?? b ?? c
is evaluated as
C#
a ?? (b ?? c)
The ?? operator can be useful in the following scenarios:



Paanch:

Peek -- points to an oldest element in the queue without removing it.

Example:

Queue<string> myQueue = new Queue<string>();

myQueue.Enqueue("1");
myQueue.Enqueue("2")

Then,

myQueue.Peek(); //will result "1"

Chaar: WPF Programming and C#






Adding with Kristin's answer, There is no difference in performance because after compile they generate same IL code for the same query. Language Integrated Query (LINQ) is feature of Visual Studio that gives you the capabilities yo query on the language syntax of C#, so you will get SQL kind of queries. And Lambda expression is an anonymous function and is more of a like delegate type. All lambda expressions use the lambda operator =>, which is read as "goes to". The left side of the lambda operator specifies the input parameters (if any) and the right side holds the expression or statement block. Personally I like Lambda Expression. Hope this helps you.


Chaar:

XMLSerializer class when used together with a Text Writer allows you to store C# structure to XML file but we lose the top element of the generic array collection.

To avoid this, serialization can be improved by using XmlRoot attribute. Example:

List<Person> personList = FormTouristList();
XmlSerializer xmlSerializer = new XmlSerializer(List<Person>);

[XmlRoot("PersonList")] can be used while serializing to avoid losing the top element.