Showing posts with label C#. Show all posts
Showing posts with label C#. Show all posts

Thursday, 7 May 2020

if – if else – if else if ladder in C#

C#  IF Statement :

Syntax :

if(condition)
{
//code to be executed
}

Prog : Write a program to test whether a number is even or not





C#  IF-ELSE Statement :

Syntax :

if(Condition)
{
// code to be executed
}else
{
//Code if condition is false
}

Prog : Write a program to test whether a number is even or not




C# IF - ELSE - IF LADDER Statement :

Syntax :

if(Condition1)
{
//code to be executed
}else if (Condition2)
{
//code to be executed
}
else 
{
//Code when all the condition are false
}


Program : Write a program to print Grade of Student as per Marks.



Sunday, 3 May 2020

Integer and Decimal value in C#

In this blog, we will discuss about
  • C# Integer Datatypes
  • C# Decimal Datatypes
C# Integer Datatypes :
  • We can only store whole number in them
  • Whole Number mean number without any decimal such as 34, 204, 35 etc
List of C# Integer Datatypes
  • byte
  • short
  • int
  • long
 The difference between all these integer datatype how big value we can store in it.

- Byte 
  • sbyte can store value between -128 and 127.
  • byte can store value between 0 and 255.
- Shot 
  • short can store between -32768 and 32767.
  • ushort can store between 0 and 65535.
- Int 
  • int can stor value between -2147483648 and 2147483647.
  • uint can store value between0 and 4294967295.
- Long 
  • long can store value between -9223372036854775808 and 9223372036854775807.
  • ulong can store value between 0 and 18446744073709551615.
How to declare variables in C#
- General Syntax
      DataType VariableName = value;

Examples
  • sbyte scoreSbyte;
  • byte ageByte;
  • short studentIdShort = 5;
  • int studentIdInteger = 43;
Design Example :
- What will be datatype for Age?

Human can live these days at most, 120. Make it 150. so byte is best.
But In older days from history, we find that many people lived for around 1000 years, so Short is best.
What if the Age is relating to Historical Site or Historical Events (Big Bang), which may be thousands or million of years old then int is best.

C# Decimal Datatypes:
  • We can store decimal numbers in them
  • We can also store Whole number in them
  • For example , 34.5, 204.3, 35.7 etc.
List of C# Decimal Datatypes
  • float
  • double
The difference between all these decimal datatype how big value we can store in it.


Example 
  • float salaryFloat = 101.5f;
  • decimal salaryDecimal = 101.25m;
  • double salaryDouble = 101.5;

Sunday, 26 April 2020

What is Variable, Datatype and C# Datatypes

Variables :
  • It is location in memory (RAM) to temporary store a value during execution of Program / Software.
  • As the name suggests, the value of variable can change during execution of program.
  • A variable is made of 3 things.
                - Datatype
                - Name
                - Value (optional)

DataType :
   - It means what type of value we can store in the variable.
  • Numbers such 123, 10.50 etc
  • Strings such as UK, Canada etc
  • Data such 11/4/2020

Name :
  • It identifies the variable. For example, firstName, lastName, age
Value :
  • What actual value is stored in variable.
List of DataTypes in C# :
  1. Integer → Numbers such as 120, 345 etc
  2. Decimal → Number such as 3.5, 4.5 etc
  3. Char → Single character such as A,a,B,z
  4. Bool → True or False value
  5. String → More than one characters value such as John Smith, Mark Smith, Canada , Landon etc.
Syntax :
              DataType variableName = value;

Naming Rules :
 一  Names may consists of letters (A-Z or a-z), digits and underscores
  •  e.g firstName, firstNumber, _Age, firstNumber1 (correct)
  • #FirstName, @Email (wrong)

一 Name must begin with a letter or underscore.
  • e.g. firstName or _firstName (correct)
  • 1stName or 2ndNumber (wrong)
一Name must not have spaces.
  • e.g. first Name (wrong)
  • firstName (correct)
一 Names must not have reserved word or C# keywords. List of C# keyword are shown in the table.




Naming Conventions :
ー Names must be meaningful
  • e.g. firstNameString, cnicString, studentldlnteger (correct)
  • a,b, obj1 (wrong)
ー  Name must include its datatype
  • e.g. firstNameString, cnicString, studentldlnteger (correct)
  • FirstName, firstname, CNIC or Studentld (wrong)
ー Name must begin with lowercase letter and then capitalize each word of the name
  • e.g. firstNameString, cnicString, studentldinteger (correct)
  • FirstName, firstname, CNIC or StudentId (wrong)



Introduction of C# | First C# Program | C# Vs Java |

C# Introduction 
  • Computer Programming : It is a process of creating computer programs or in other word software to solve particular problem. 
               - Word Processor
               - Hospital Management
               - Spreadsheet
  • It is a Object Oriented Programming Language from Microsoft Corporation in year 2000.
  • C# is a part of .Net Framework and currently in version 16.3.
  • It is helps in developing variety of application such as windows based, Database based, Web Services, Web Application and more. 
C# Vs Java : Both are Object Oriented

C# - 
  1. Required CLR (Common Language RunTime)
  2. GOTO Statement is present
  3. Support Structure and Unions
  4. Support Unchecked Exception
  5. Less Secure than Java
Java -
  1. Required JRE (Java Runtime Environment)
  2. No GOTO statement 
  3. No Structure and Union
  4. Supports both Checked and Unchecked Exception
  5. Much Secure
First C# Program :-

Popular Posts

Categories

Android (21) AngularJS (1) Assembly Language (2) Books (10) C (75) C# (4) C++ (81) Data Strucures (4) Downloads (1) Engineering (13) FPL (17) Hadoop (1) HTML&CSS (38) IS (25) Java (87) Leet Code (4) PHP (20) Python (214) R (69) Selenium Webdriver (2) Software (14) SQL (27)