Posts

Difference between static members and instance members

Introduction  Instance members are unique to each object of the class, whereas static members are the same for all objects of a class. Let's say we have a class named 'Student.' Each student will have a different name, ID, and address. However, the name of the school is going to be the same for all students. So the name of the school can be declared as a static member, whereas the other attributes of the student can be declared as instance members. Example: This is an example of a class named Student class Student {     public string Name ;     public int ID ;     public string Address } Let's now create 2 objects of this class Student. The instance variables of the students have its own unique values as you can see below. Student Vipin = new Student (); Vipin . Name = "Vipin" ; Vipin . ID = 20409068 ; Vipin . Address = "Bangalore" ; Student Neethu = new Student (); Neethu . Name = "Neethu" ; Neethu . ID = 1234 ; Ne...

Basics of LINQ in C#

Image
Introduction LINQ is nothing but a language-integrated query language. This helps developers query data from various data sources like XML, collections, and databases, among others. The following are the key features of LINQ: Query Expressions : We can write code very similar to SQL language to query data. This makes it easy to read code and filter data in a familiar way. Standard Query Operators : Standard query operators like the WHERE clause, GROUP BY, ORDER BY, and JOIN are supported. LINQ to Objects : We can query in-memory objects like arrays, lists, and dictionaries using LINQ. LINQ to SQL : LINQ can be used to query relational databases. We can write strongly typed queries, which means that these queries are checked for correctness at compile time rather than runtime. The framework converts the query into actual SQL statements so that it can be executed in the database. LINQ to XML : We can query XML using LINQ. For example, we can loop through each repeating record in XML and ...

Basics of scope in C#

Introduction Scope in programming is a concept that determines where in your code you can access a particular variable or identifier. It's like defining the boundaries of visibility and usability for different parts of your code. Let's explore scope with a bit more depth Local Scope: Variables defined within a specific block of code, such as a function or a code block enclosed within curly braces { }, have local scope. They are only accessible within that block of code where they are declared. Outside of that block, they are invisible and cannot be used. Local scope helps in encapsulating data and preventing unintended interference with variables in other parts of the program. Global Scope: Variables declared at the top level of a program, outside of any specific function or block, have global scope. They can be accessed from anywhere in the program, including inside functions and code blocks. Global variables are available throughout the lifetime of the program, which can make...

Basics of List in C#

Introduction  In C#, a List<string> is a data structure that allows you to create a list of strings. Think of it as a dynamic container where you can store a bunch of text (strings) and easily perform various operations on that list. Here's a more detailed explanation with an example: Concept: List of Strings List: A List<string> is like a collection of strings stored in a particular order. It's similar to having a list of items you can keep track of. Strings : Each item in the list is a string. A string is just a piece of text, like a word or a sentence. Example: To-Do List Imagine you have a digital to-do list on your computer. It's a List<string>, and you can add, remove, and check off tasks. Here's how it works: using System ; using System . Collections . Generic ; // This is needed to use List<string>. class Program {     static void Main ()     {         // Create a List<string> for your to-do list. ...

Basics of dictionary in C#

Introduction In this blog, we will understand the basics of a dictionary in C#. The dictionary is a collection of key-value pairs. When we create a dictionary in C# we need to specify a type for the key and the type for the value. Dictionary class is present in the " System.Collections.Generic " namespace.  The fastest way to find a value within a dictionary is by using its key. The keys within the dictionary must be unique. Example: Phone Book Dictionary Imagine you have a phone book, which is like a dictionary in C#. In this phone book, you want to store people's names (keys) along with their phone numbers (values). • Keys : The names of people are the keys. Each name is unique, just like words in a real dictionary. • Values : The phone numbers are the values. Each name (key) is associated with a specific phone number (value). Here's what it looks like: "Alice" is a key, and its associated value is her phone number: "555-1234". "Bob...

Enforcing Uniqueness in Multiple Fields of a Database Table

 Introduction There are situations in which we need to ensure the uniqueness of not just one, but multiple fields within a database table. While the primary constraint is suitable for ensuring uniqueness in a single field, there are scenarios where we need to enforce uniqueness across several fields. In such cases, the ideal solution is to employ a unique key constraint. Code To illustrate this concept, let's consider a scenario where we want to enforce uniqueness in a specific field, such as the ' InvoiceNumber ,' within the ' EDIInboundInvoiceHeader ' table. In this case, we can achieve this by adding a unique key constraint. A sample code is given below. Alter table EDIInboundInvoiceHeader Add Constraint UQ_EDIInboundInvoiceHeader_InvoiceNumber Unique(InvoiceNumber) Code Walkthrough ALTER TABLE EDIInboundInvoiceHeader: This part of the SQL statement indicates that we are making alterations to the 'EDIInboundInvoiceHeader' table. In SQL, the ALTER TABLE co...

Exploring the Compilation of a C# Program

 Exploring the Compilation of a C# Program When the C # program  is compiled, the compiler converts the C# source code to an intermediary language called IL code. Imagine IL code as an universal language, comprehensible to any computer compatible with the .NET framework. It is also sometimes called as MSIL which stands for Microsoft intermediary language. The Role of IL Code IL code serves as the bridge between our abstract, high-level C# code and the low-level, machine-specific language that our computers understand. It's an essential step in making our programs adaptable across different environments. Assembling the IL Code The IL code is encapsulated within what is known as an "Assembly." This assembly acts as a container, housing not only the IL code itself but also crucial metadata about our program, such as its identity and version. Typically, assemblies carry the file extension ".dll" when they contain libraries and ".exe" when they're execu...