Wednesday, October 14, 2020

C# Variables and Their Data Types

Introduction

Variables are temporary data storage memory locations which store program data.

The variable has a name and type. C# is a strongly typed language that means we must declare variable type at the time of declaration.

Rules For Declaring Variable Name

Variable Name must start with an English alphabet letter, _ or @ symbol. The first letter can be either lower case or upper case.

Example of Valid Variable Name declarations: 

fullName;

FullName;

@FullName;

_EmpSalary;

In the middle or at the end of Variable names we can also use English letters that can be either lower or upper case, numbers and underscore ( _ ).

Variable Names are case sensitive, that means someVar and somevar considered as two different variables.

No white space is allowed between variable name, means that full Name is an invalid variable name but we can use underscore ( _ ) character to join words example full_Name is a valid variable name. We can also use camel case to join two words where the first character of second word must be capital for example fullName.

We can use numbers in variable Name but not at the beginning, but we can use numbers in the middle or in the last character example 1stnumber is invalid but number1 is a valid variable name.

We can not use C# keywords as a variable name. It is recommended to choose a variable name in a way that it describes the value that they stored, for example,  courseName is a good choice for storing course name.

Example of Variable Declaration:

syntax of variable declaration

<data_type>  <variable_name>

Where data type must me valid C# data type (we will discuss soon) and variable name must be a valid identifier as we already discussed above.

string courseName;

where string is a data type and courseName is the name of our variable.

where semicolon ; indicates the end of statement in C#.

How we assign value to our  variable.

variable_name = value_to_assign

we always put our variable name on the left side and value to assign the variable on the right side and use operator is also called the assignment operator between them.

courseName = "C# Programming";     <------ The assigned value is in double quotes

The Point to be noted here that we put the assignment value, in the inverted ( " " ) commas, because our variable type is a string and string is nothing but stores the array of characters.

When we execute the following C# code it will print the value of our variable.

Console.WriteLine(courseName);

OUTPUT : C# Programming


Alternative way to declare a variable

string courseName = "C# Programming";

In the above statement, we assigned the value to our variable at the time of declaration.

How To store a single character

For storing a single character we used char data type in C#

char yourGrade = 'A';     <--------- The assigned value is in single quotes

Where char is a data type and yourGrade is a variable name.

We always assign a value to char data type within a single quote as opposite to a  string which requires double quote.

When we execute the following code.

Console.WriteLine("Your Grade is: " + yourGrade);

Then the output will be:

Your Grade is: A 


How to store numbers in C#

For storing whole numbers in C# we used Integer data type.

Example of Integer variable declaration

int number1;

int number2;

Where int is Integer data type and number1 and number2 are our variable's name.

How To Add Two numbers in C#

int sum;    <-------- here we declared a third variable which stores the sum of our two variables.

number1 = 20; <---------- here we assign the value to variable number1

number2 = 4; <--------- here we assign the value to variable number2

The most important point to be noted here that when we assigned the values to our Integer variables we were not using (" "), because it is only used when data type is string.

sum = number1 + number2;

When we run the following command 

Console.WriteLine("Sum of Two numbers is : " + sum);

The Output of the above code will be Sum of Two numbers is :  24

Where "Sum of Two numbers is :" is a string value which we are providing to our Console.WriteLine( ) and we used the + sign and then our variable name sum. Here our variable value is passed as a string to Console.WriteLine( ) and we used + sign because we are concatenating two strings.

We can also use long data type to store whole numbers, but only when need to store very large values.

How to work with Real Numbers in C#

To store real numbers we mostly use three data types

float height;

double pi;

decimal weight;

where floatdouble and decimal are data types and height, pi and weight are variables name.

The actual difference between these three data types is that how big decimal value they can store.

Here we assigned values to our variables storing real numbers

height = 4.9;

pi = 3.14159;

How To Work With Logical Variables in C#:

For logical values we use bool data type in C#. The yes value represents true and no value represents as false in bool data type.

Example of bool 

bool IamADoctor = false;

bool IamAProgrammer = true;

Where bool is a logical data type

When we execute the following code in C# 

Console.WriteLine(“Is I am a Doctor :  + IamADoctor);

Console.WriteLine(“Is I am a Programmer :  + IamAProgrammer);

It will produce the following output.

OutPut 

Is I am a Doctor : false

Is I am a Programmer : true


Declaring Multiple Variables

We can also declare multiple variables in a single line.

For Example:

int a,b,c,d;

Where int is our data type and a,b,c,d are our variable names each separating by comma (,).

Below is a C# Data Type Table given so you have a better idea.


These are some basic Data Types which we had discussed here, there are some other Data Types too. Which we will discuss in our upcoming articles as we need them. 

Here is a YouTube video Link of my C# Variables And Their Data Types tutorial (Urdu/Hindi language)


Written By

Syed Sohail Ahmed Quadri

YouTube Channel

Right Way Learning

Friday, October 9, 2020

C# Programming Introduction

C# is a programming language like Java, C/C++. It is developed by Microsoft and it runs on .NET Framework or .Net Core Framework.

.Net Framework runs only on windows OS but .Net Core is a cross platform framework it can runs on Linux, macOS, windows.

With C# we can develop web applications, desktop applications, mobile applications, games and much more.

C# is an object oriented programming language.

Tool we need to develop C# programming application are visual studio or visual studio code.

In this tutorial series we will use visual studio community edition which is free to download.

C# inherits its basic syntax from C/C++ if you know these two languages you feel home.

Special Notes

C# is a case sensitive language. Incorrect case prevent program from Compiling successfully.

C# application consists of the following parts

  • Declaration of Namespace
  • Class
  • Methods of Class
  • Attributes of Class
  • Main method declaration (starting point of every console application)
  • Statements 
  • Expressions
  • Comments 

Structure of C# Program

Following is a code written in C# programming language

using System;
 namespace HelloWorld
 {
  class Program 
{
  static void Main(string[ ] args) 
{
  Console.WriteLine("Hello World!"); 
                                   /*This is a comment in C# */
}
  }
 }

Explanation Of the above Code


using System;

using keyword is used to import existing classes, so we can use classes in our program define in System namespace.

;

semicolon after the end of every statement is a must in C#,  basically semicolon is a statement terminator.

namespace HelloWorld

namespace is a container for classes and files and "HelloWorld" is the name of namespace in our code.

 {    this curly brace marks the beginning of our namespace.

class Program 

this above instruction declares our class and the name of the class is Program. When we create our console application in .Net framework the " Program.cs " file is  automatically created by the framework which has a class name Program.

 this curly brace right after the declaration of our class marks the beginning of  class code.

static void Main(string[ ] args) 

Every console application has at least one Main( ) method and it is the entry point or starting point of our application, code inside this Main( ) method will be executed.

 this curly brace right after the declaration of our Main( ) method marks the beginning of our Main( ) method.

Console.WriteLine("Hello World!"); 

This Console.WriteLine(  function which is define in System namespace print the " Hello World! " on the Console.

 /*This is a comment in C# */

This above line is a multiple line comment in C# and will be ignored by the C# compiler.


}
  }
 }

These above three curly braces marks the closing of each curly brace which we had open previously in our above code.

When This above code executed it display the following output on the console.

Output

Hello World!


Here is a YouTube video Link of my Introduction To C# Programming tutorial (Urdu/Hindi language)




Written By

Syed Sohail Ahmed Quadri

YouTube Channel   Right Way Learning




Friday, October 2, 2020

Dot Net Core 3.0/3.1 Project Structure As a Back End

Understanding Dot Net Core Files and Folders Structure

When working on Dot Net Core as a Back End the project divides in the following main components and files (We are using Angular as a Front End in this project and Angular project structure already discussed in my previous article).

Connected Services

With Connected Services we can bring Azure workflow into Visual Studio for Mac. For example, you can add an Azure back end services like cloud data storage and authentication.





Dependencies

This folder contains all the internal, external, and third party references required to build and run our project. 








Analyzers helps you maintain high quality code, it can raise  errors/warnings/suggestions when you write less-than-ideal or plain low quality code. 

Frameworks displays the framework used in the project. Here we can see that Microsoft Net Core is the framework installed.

Packages folder shows currently installed packages, it also shows NuGet package references added for this project, which we will install later as we need them. In the package folder we can see that we have Microsoft.AspNetCore.SpaService.Extension is installed it is for supporting single page application in our case it is an Angular.

Properties

The properties node contains launchSettings.json file, this file only used when we use our 
application in local development machine or in debug mode. This file has nothing to do when we publish our application. 








Here we can see in the file that ASP NET Core environment is Development.

And also we have two profiles IIS Express profile this profile will be used whenever we launched our application in debug mod, it is related to internet information server. 

Other profile is related to our application FirstProject. This profile setting will be used whenever we start our application in console mode by running dotnet run command.

Controller

Which has been shipped with any MVC-based ASP.NET application   since the preceding release of the MVC framework.

Controller handles all incoming requests from the Client ( Angular in our case) and send response back to the Client (Angular) mostly in JSON format.





















Here we can see that WeatherForecastController is our controller name and it handles all the incoming requests destined for this controller. We will discuss more about Controller in upcoming articles.

Page

which contains a Razor Page file Error.cshtml to handle runtime and/or server errors. Whereas _ViewImports.cshtml file provides the mechanism to include directives globally.






Configuration

For the configuration of dot net core back end, such as modules, middleware compilation setting and project publishing we used three important files which are appsettings.json, Program.cs and Startup.cs.

appsetings.json: this file contains the setting information such as default connection string for connecting to the database.


Program.cs : dot net core mainly a console application and like every console application, Program.cs has a Main( ) method and this file is the starting point of our app.



















Main( ) method starts the CreateHostBuilder() then this method configure logging, dependency injection and then further configure  Kestral webserver also look at the configuration files such as appsettings.json and finally starts the Startup.cs file.

Startup.cs: This class is compulsory in dot net core application. Startup is a generic name we can give it any name to this file but we have to define it in webBuilder.UseStartup<>. 



















Startup class configures the Http request pipeline and utilize the Configure( ) method by adding the required middleware. 

This class also has a ConfigureServices( ) method and in this method we can add and configure required service and dependency injection.

Here is a YouTube video Link of my Dot Net Core Project Structure tutorial (Urdu/Hindi language)



Written By

Syed Sohail Ahmed Quadri

YouTube Channel



Saturday, September 26, 2020

Angular Folder Structure in Visual Studio 2019

 

In visual studio Angular Front End contains under the ClientApp folder.



   e2e folder
   (E2E)  means end to end testing and also known as integration testing provides a
   automatic simulation  by which we can make sure that our application works correctly
   and components are communicating with each other accordingly and producing 
   the desired functionality.


In Angular protractor is a framework which provides power full testing tools and technologies protractor.conf.js file provide configuration setting for the protractor framework.

src folder
This folder contains all the main code files which we will create and work around in our Angular project.  


app folder 
When we create Angular project, the default app module will be automatically created. 

Every Angular application must contains at least one module and one component. 
  
Inside app folder we can see that there are few folders includes counter, fetch-data, 
home,  nav-menu which are components of our app. Inside components we define our application logic and data.



As we can see that each component has its own HTML and TypeScript file and also counter component has specification file which provides unit testing for the component. When we create component in Angular .css file also created in which we can define style for the component it is an optional choice as we can see it in our nav-menu component.







app.component.html this file contains the HTML code it is a template file used to bind the data for Angular.
app.component.ts this is a typescript file provide logic to our component.
app.module.ts this is also a typescript file it contains all the dependencies for our  app we will import needed module for our app here and also declare component to be use in the app.

Some other important files in the Angular Project Folder.

          package.json

 It is the npm configuration file. It contains information of packages and  dependencies installed in our web application.

         package-lock.json

    This file automatically generate the information when npm package manager runs, this file store the npm operation.

    angular.json

     This file contains information related to workspace configuration and project specific configuration and provides default setting for the build and development tools provided by Angular CLI.

    .gitignore

     this file stores the information related to Git operation and tells the Git which files to ignore.

    .editorconfig

     This files maintains the consistency related to code editor operation.

    Assets folder

    This folder contains those files which are not modify during compilation such as images.

    Environment folder

    contains files which provide default environment for the configuration.

    Browser list

    In this file you can define your target web browser.

    favicon.ico

    It is a small graphic image file which represent your website brand in the web browsers.

    Index.html

    when some one visits your website this files serves first.

    main.ts

     It is the main entry point and it is .ts file it will start the JIT compiler and compiles your application.

    polyfills.ts

    This file contains polyfill scripts to support the web browsers.

    test.ts

    It is the main unit test file in your project.

    styles.css

    It is a Global CSS file which provide style support for  your application.

    tsconfig.json

    This file specifies the configuration options for the TypeScript compiler.


    tslint.json

    This file provide configuration information for the TSLint for the current project.


Here is a YouTube video Link of my Angular Dot Net Core Folder Structure tutorial (Urdu/Hindi language)




Written By

Syed Sohail Ahmed Quadri

YouTube Channel






Thursday, September 24, 2020

Introduction To Full Stack Dot Net Development

 WHAT IS MEAN BY FULL STACK DEVELOPER

A software engineer who works both on the Front End like (Angular, HTML, JavaScript, CSS, Bootstrap, jQuery) and Back End like (ASP.NET Core, PHP, Python, Java, Database).

It means that it is necessary for a full stack developer to work both on Client Side as well as Server Side. The main reason behind is that he/she has to work on both ends (front end/back end) when developing an application.

Full stack developer has an interest in all software technologies.

WHY WE NEED FULL STACK DEVELOPER

 Here are some prominent reasons why you should hire a full stack development professional.

full stack developer helps you to keep every part of the system running smoothly.

full stack developer can provide helps to everyone in the team and greatly reduce the time and technical cost of team communication.

If one person can plays different roles, it saves your company’s personnel, infrastructure and operational  cost.

Learning Approach

In this series of articles we will discuss the Angular + Dot Net Core full stack learning approach. For the design of database we will use code first approach with entity framework core.

Learning Angular and Dot net core together means that you can become full stack dot net developer. So by learning these two technologies you can design front end in Angular and back end in Dot Net Core and you can produce complete web application of your own.

Working Diagram




What is ASP.NET Core

It is developed by Microsoft. ASP.NET Core is a cross platform Framework. Cross platform means it can run on windows, Linux and Mac OS. ASP.NET Core is also an open source light weight and high performance. It is a modern web framework by using that you can develop cloud based and also internet connected applications.

What is Angular

Angular is a framework and development platform for building efficient and sophisticated single-page web applications. Angular is typescript based platform, it is also open source and developed by Google.

Advantage of Angular

Angular is just a single framework you need to learn whether you are interested in developing for mobile application or for a desktop web application.

What is Single page Application

Angular is a single page application development framework (SPA) that means it dynamically rewrite the current page with new data from the web server instead of loading entirely new page which is a traditional approach.

Here is a YouTube video Link of my Full Stack Dot Net Development tutorial (Urdu/Hindi language)




Written By

Syed Sohail Ahmed Quadri

YouTube Channel

Right Way Learning






Introduction To Full Stack Dot Net Development

  WHAT IS MEAN BY FULL STACK DEVELOPER A software engineer who works both on the Front End like (Angular, HTML, JavaScript, CSS, Bootstrap,...