C#: TYPES

In continuation of our C# lessons, our today’s topic is types. In C# there are two types: Reference types and value types. 

  • REFERENCE TYPES: Reference Type Variables always store references to their data. We can have multiple variables pointing to the same objects or we can also have multiple variables pointing to multiple objects.
  • VALUE TYPES: Value Type variable contain their data directly. They don’t hold a memory address. For example integers and floats.

Value type can be created by using either struct or enum keyword. Struct is like a class definition. Structs are meant for special cases when you need to write an abstraction that represents a single value. Whereas enum (enumeration)is used to create constants that that will hold numerical vaue.

Value type variables are immutable i.e. they cannot change. We can’t change their value once created. We still call them variable because the daa inside can vary but the actual value remains the same.

ARRAYS

An array is a reference type and is a simple data structure to manage collection of multiple objects or values. When we create an array we have to specify its size. One more thing about an array is that the first item in an array is at index 0 not 1

C#: ASSEMBLIES

Moving forward on the C# lessons, today we will discuss about assemblies in C#.

Assemblies are C# compiler created files, which contains code written for our application.  These are the building blocks of .NET Framework applications.

The Visual Studio and C# compiler will compile our code into an assembly

.NET Assemblies are files can be stored on the disk with a .exe or .dll extension and by default the assembly name will have same name as the project.

  • .exe:  It stands for executable. An exe file be executed directly either by double clicking file on Windows or by using the program name from command line.
  • .dll:  It stands for dynamic-link library. The file with dll extension can never be executed directly but it can be loaded by another program and use the code inside. Hence, dll is good for the code that you want to reuse in multiple applications.

 

The above is the solution explorer window of Visual Studio and under the references, various assemblies  be seen. It is okay to remove one of them which is not in use by our program. But we can’t remove the other as it will give an error while executing the program.

If we want to use a class defined in another assembly, we must have that assembly loaded in the memory with our program. This can  happen automatically with the .NET runtime. The simplest way is to establish an assembly reference. To do this, just right click on the reference node and select Add Reference. This will give us the list of assemblies from .NET framework and defined by other projects, to select.

UNIT TESTING

We often needs to test the code written to check whether or not its working properly. A unit test is where we can write our C# code to test other C# code in automated manner. Tests are the code inside the test methods that are in test class. For this we need to create a new class and in this we have to use namespace  Microsoft.VisualStudio.TestTools.UnitTesting. Then add the rest of the code. One thing to keep in mind is to change the access modifiers to public in the programs, which we are going to test, otherwise it won’t work.

C#: CLASSES AND OBJECT

Today we will discuss about classes and objects in C#.

CLASSES: Class, as we know, tells us about the methods used in our program. In other words it gives a blueprint for data type. In C# we write class to implement features in software.

A class can be considered as a cookie cutter. A cookie cutter shapes cookies and these are cookies, we work with but cookie cutter is only one and exists only to give a specific shape to our cookies. Similarly, we don’t work with class definition. We use it to create objects with specific and consistent shape.

Sometimes class keyword is used after a access specifier, which specify the access rules for the members as well as the class itself. The default access specifier is private.

OBJECTS: Objects can either be stored in a named variable (which we are using now) or in an collection of array (which we will learn in future). An object is basically a block of memory that has been allocated and configured according to the blueprint.  As discussed earlier, a blueprint refers to the class in our program.

  • CONSTRUCTOR: When we instantiate a class, it invokes a special method to help create an object. this special method is called constructor. A default constructor does not have any parameter but if you need, a constructor can have parameters. Such constructors are called parameterized constructors, which assigns an initial value to an object.

DIFFERENCE BETWEEN CLASS AND VARIABLE:

We know that a class is a blueprint for creating an object. We can use new keyword with class to create a new object for us. A class can also be used to declare the type of variable.

However, a variable is nothing but a name given to a storage area that our programs can manipulate. Each variable in C# has a specific type, which determines the size and layout of the variable’s memory the range of values that can be stored within that memory and the set of operations that can be applied to the variable. This can be done by various methods and using class is one of those methods.

C#: PROGRAM STRUCTURE

In the last post, I talked about C#. In the continuation, today I will discuss about the program structure and basic syntax.


using System;

namespace Hello
{
        class Program{

                         static void Main(string[] args)
{
                             Console.WriteLine(“Your name:”);
                             string name = Console.ReadLine();

                             Console.WriteLine(“How many hours of sleep did you get last night?”);
                              int hoursOfSleep =int.Parse(Console.ReadLine());

                              Console.WriteLine(“Hello,” + name);
                              if(hoursOfSleep > 8)
{
                              Console.WriteLine(“You are well rested”);
}
                              else
{
                                      Console.WriteLine(“You need more sleep”);
}
}
}
}


This is the syntax of the program from last post. If we look at the different parts of the program, we will see :

  • USING SYSTEM: The very first line and it is used to include namespace in the program.
  • NAMESPACE DECLARATION: It is the part under which classes are declared. In the above example, Program class is declared under Hello Namespace.
  • CLASS DECLARATION: In the next line, a class named Program is declared. A class usually contains the methods and attribute that our program is going to use.
  • MAIN METHOD: It is the most important part of the program. The Main method describes the behavior of our program when executed. For instance, in the above syntax the main method contains Console.WriteLine(“some text“) which is the method of console class and this results in the display of the text on screen. In a similar way, Console.ReadLine() is used to accept a value from user.

Apart from this If-Else statement is used which is a condition. It will only be executed when our expression fulfills the given condition.

Some points to keep in mind while writing C# syntax:

  • It is a case sensitive language
  • A semicolon(;) must be put after the end of expression and statement
  • Execution of program always commence with Main method
  • Comments can be added using /* —text—–*/

 

C#: AN INTRODUCTION

I am looking forward to learn C# now and I have started a path in order to learn C#. It includes all the courses on pluralsight on C#. Here is my first approach towards this. The first course I am doing is C# Fundamentals with Visual Studio.

C# is a general purpose object-oriented programming language. It is a popular programming language used to write programs that run tablets, phones, web servers and desktops.  The tool I am learning to use is from Microsoft named Visual Studio.  Once we write our application in C# with Visual Studio, it runs on .NET Framework, and then it can take advantage of services and programming interfaces that the framework provides.

.NET framework consists of two distinct parts: CLR and FCL

  • COMMON LANGUAGE RUNTIME (CLR): CLR is an execution environment for .NET applications and brings our applications to life as well as managing it during its execution. It looks after all those factors which are required for smooth execution of our application. Hence, we don’t need to care about memory usage of our application and the version of the operating system we are using as it is the responsibility of CRL.
  • FRAMEWORK CLASS LIBRARY(FCL):  It is a library that includes Softwares. It is something with which a user interacts the most as it contains reusable software that is used to build applications. It provides all the functionality to do useful work.

.NET gives us the CLR to run our application and FCL to give us software components.

Today, I started typing along with the course video, which was really fun. It is very useful tip while learning programming.

I commenced by following all the instructions and at the end, I created a simple program.

In this the commands used are

  • Console.WriteLine to print the lines (Your name,  How many hours of sleep did you get last night? and You are well rested/ You need more sleep),
  • String to enter characters,
  • Console.ReadLine (for the user to enter data)
  •  if else statement.

And here is the output:

SQL Server

This week, I learnt some more things about databases and SQL Server. The learnings of this week are:

  • CONSTRAINTS: These describe the limitations on the data in the table and hence, ensures the reliability of the data. For example, we can specify that a column doesn’t have a null value.  If there will be any violation, the action will be aborted. In a similar way, we can set a default value or null value to the table.
  • PRIMARY KEY: It is that special feature of a table which uniquely identifies each record in the database table. It represents the unique value of table and thus, prevents the duplicity of data in the table. A primary key with more than one field is called composite key. For instance, in a table of employees of an organisation, the employee ID would be the primary key. It can never have a null value.

The primary key of one table is called Foreign key in another table.

  • SELECT: SELECT statement is used to fetch data, in other words, make queries from a database table.

Following is the syntax used for a select statement:

SELECT column1, column2, columnN FROM table_name;

The SELECT statement is usually followed by various clauses to limit the query. these clauses are WHERE(to add specific condition), DISTINCT(to avoid duplicate values), FROM(to mention an address of the table from the database), LIKE(to specify a pattern in a column and is oftenly used with wildcard characters like %).

  •  WHERE CLAUSE: As mentioned above it is used to add a particular condition. But it is not limited to SELECT statement. It is also used with DELETE, JOINS and UPDATE statements. We can limit our result using it. For example, in the table of employees, if want to search for workers in any particular department say marketing we can type:
SELECT column_name 
FROM table_name
WHERE [department= marketing ]

It will give the details of all the employees in the marketing department.

  • JOINS:  This is used to create a new result set of a table after combining the rows from two or more tables. There are different types of join statements.

Among these, CROSS JOIN is least useful as it produces the result table with the method known as the cartesian product. If we are joining two tables which have 100 rows each, the result table will have 10000 rows. Hence we can conclude it results into duplicity of data.

The most commonly used JOIN statement is INNER JOIN. It creates a new result table by combining column values of two tables after comparing each row of table1 with each row of table2 to find all pairs of rows which satisfy the join predicate. It is followed by ON clause, which is used for mentioning the common fields(join predicates).

  •  INSERT and UPDATE:  These are used to insert a new row and update an existing data in the table.

For insert:

INSERT INTO TABLE_NAME (column1, column2, column3,...columnN)  
VALUES (value1, value2, value3,...valueN);

For update:

UPDATE table_name
SET column1 = value1, column2 = value2...., columnN = valueN
WHERE [condition];
  • COUNT: This command gives the count of rows in the column specified in the query.

SQL and Database

This weekend, I have completed another Pluralsight course named ‘Introduction to SQL’.It was about SQL(Structured Query Langage), which is a special- purpose programming language, used to manipulate a relational database. The course was about how we can create, query, update and delete data in a database.

A database is like a container where we can organise data in a useful or constructive manner and relational model is a way to describe the data and the relationship between those data entities.

I ended up learning a lot of new things that include:

  • Naming conventions in SQL
  • SELECT  Statement, which is used to make most of the queries in SQL, and is followed by various clauses depending upon the query like as FROM, DISTINCT(for limiting the result set), WHERE, LIKE, IN, IS and IS NOT and operators such AS and, or.
  • how to sort the result set in a specific order (using ORDER BY)
  • set functions (COUNT, MAX, MIN, AVG and SUM)
  • how to put all subsets together and link them up to the columns specified inGROUP BY clause
  • how to join two or more tables together. This can be done by various ‘joins’ like as CROSS JOIN (least useful), INNER JOIN, OUTER JOIN (FULL, LEFT and RIGHT)
  • CRUD (Create, Read, Update and Delete). This is about how to insert new rows in a table (using INSERT INTO), read data in tables (using SELECT), update the existing data in a table (UPDATE) and delete data from a table (this must be done carefully as it can delete the whole table, so it is better to use TRANSACTION command before this to rollover if you delete the wrong data).
  • using ALTER TABLE to change anything in a table, unless the data in the isn’t conflicting with the change.
  • DROP TABLE which is used to remove a table from database permanently.

I felt that it isn’t much difficult but the only need is to practice hard in order to master the use of commands in SQL.

Introduction to Computer Programming

Introduction to Computer Programming or COMP115 is another unit(subject) I am enrolled in. This is about programming in processing language. We can use it to draw various things. The only thing we need to manage is the x- and y- coordinates. But I think one can learn it by practice. In my first week I have learnt the basic things.

This covers pixels and variables i.e. how to draw:

  • point
  • line
  • rectangle and square
  • circle and ellipse
  •  triangle

This may sound hard but once you start, you will know how easy and simple it is. This is all about the magic numbers( the values of X- and Y- co-ordinates).

This is genuinely an enjoyable subject.I also drew a train using these.

Global Citizen

This was my second week at Macquarie University. The first one was orientation week and I had a good time there. I met many students and made some good friends. My classes began this week. I am enjoying this as I am enrolled in four subjects. The most interesting (but a little bit challenging) one is ACBE100 (Academic Communication in Business and Economics). As an assignment, we have to watch an episode of TED talks ‘What does it mean to be a citizen of the world?’ by Hugh Evans and take notes and then write in our words that what is a global citizen. It is a highly recommended video by me as I truly appreciate the way all things are presented by Hugh Evans.

I completed my work. This is what I think a global citizen is.

Global Citizen as the term explains itself refers to the inhabitant of the global community, not of a particular place or nation, who steps forward to eradicate global issues. In my words, the global citizen is the one who believes in universal brotherhood and completely understands the fact that we all are living on the same earth. The boundaries across nations are man-made and these borders cannot divide the global problems. Some people turn deaf ear to the topics like global warming, terrorism, poverty, Syria unrest and poverty only because they have not encountered these in their life. Unlike them, a global citizen takes these as his own problems, raises his voice against these and take steps to eradicate these as well as encourages others to make their contribution in this movement in order to make it more sustainable and long lasting. Hugh Evans said, “the whole world is our backyard”. Hence it is our responsibility to make it more beautiful by pulling out the weeds. This is what global citizens are meant to do. They make their efforts to make this earth a peaceful and liveable place for each and every person irrespective of his caste, nation and possessions.

 

 

Javascript

A few weeks ago, I have done an online course on pluralsight.com about programming named ‘Learning to Program: Getting Started’. I learnt some basics about programming using javascript. It  started with some of basic but important things one should know about the topic.

The first one is REPL, which stands for Read Evaluate Print and Loop. This means first of of all system reads the source code, then evaluate it and print the result. After this, it does the whole process again i.e. loop.

Other useful information includes:

  • the syntax rules (guidelines to write source code in javascript like case sensitivity and writing in understandable format)
  • how to resolve errors (by intentionally writing wrong source code)
  • adding  different types of variables (which helps to store data for later use)
  • creating functions with various parameters
  • adding comments (which helps to understand the code even after years)
  • adding conditions like if, else
  • creating loops (using while and do while)
  • arrays