Thursday, 25 January 2018

003 C# Data Type & Variable

C # tutorial 003 Data Type & Variable

In .Net framework variables are mainly two types. Value type, Reference type, another type is pointer type.  Any application written over the .Net Framework has some memory, called an Application memory. This memory are divided into two parts, Stack and Heap. Stack is a  type of memory which operate  in FIFO order , that is fast come fast out. We can compare FIFO operation as a dinner plate. The last dinner plate will be pull out first and then on from a queue.
              Stack store difference type variable in it . When a function or method is called, all variable related to this function or method are called, or pushed push into the stack and when the function terminate , variable goes out of scope.To work with variable, first step to declare the variable and then to initialism with the value.

              int      a;
               a=     2;

It means I am telling the computer to allocate appropriate amount of memory for integer variable and value 2 will be stored in the memory.

 For more example of variable declaration
                
          int a; //Interger type
          string a; //string type type
         bool a; //boolean type , true false
         long a; //long type
         object a; //object type
         decimal a; //decimal type
         double a; //double type
         float a; //float type
         decimal a; //decimal type

Store value into variable
                
      int a=100;
      string a="Hello";
           bool a=true;
           long a=1234578963;
           object a=new Student ();
           decimal a=12.56654;
           double a=154.5656;
           float a=15.54;
             
Here is the list of Value type Variable





Type
Size
Range
sbyte
8
-128 to 127
byte
8
0 to 255
short
16
-32768 to 32767
ushort
16
0 to 65535
int
32
-2147483648 to 2147483647
uint
32
0 to 4294967295
long
64
-9223372036854775808 to 9223372036854775807
ulong
64
0 to 18446744073709551615
char
16
0 to 65535
float
32
7 digits
double
64
15-16 digits
decimal
128
28-29 decimal places
char
Char
 A single Unicode character
bool
Boolean
Logical Boolean type
object
Object
Base type of all other types
string
String
A sequence of characters



Reference type  variable :


When a reference type variable is created , a variable is created on the Stack and actual object is created on the heap . The variable is a pointer to the actual object only.When the variable is called , the variable return this of the memory of heap .When the variable goes out of scope the, the actual object does not destroyed ,if  it has any other reference ,but if there's no other reference variable it is cleared by garbage collection methods, which is a part of dot net component.

The list of reference type : class, delegates, interface, array.

Example of Reference Type :

public class Student
{
                public string Name { get; set; }
                public int Age { get; set; }
                public Student(string name, int age)
               {
                Name = name;
                Age = age;
               }
             //....other function and methods
}

//Variable declaration of Student type
Student std1 = new Student()

Pointer type : A pointer variable is a variable which pointer  of the actual variable type. For example.

int* x;
int* y;
* mark denotes address of  operator and &  returns the address of a variable .

C # does not support pointer conversion boxing, unboxing. The pointer variable only can be convert to pointer type and integral type. Pointer variable does not support structure details.

Here is example of pointer to integer conversion.
 
int* pointer;
int a;
a = &pointer;

Here is example of integer to pointer conversion.

int* pointer;
int a;
void* pointer = &a;


Conversion type : Conversion is a feature where variable can be converted from one type to another type. There are two type of in C#. Implicit conversion an explicit conversion.

Implicit conversion : Variable can be converted to another variable without loss of data , for example int to long. If you initialism int variable 100, named it a. Another variable named b, declared as a type of long named b. Now if you write b equal to a ,the 100 will be allocated to b. This is called implicit conversion. This type of Type casting done by the compiler for one or more sub type another super type.

int a=100;
long b;
b = a;
  
Explicit conversion : Sometimes implicit conversion is not possible. If we declare a long variable and integer variable. We assign a large data to long variable and try to convert it to integer, where the integer has a range less than long variable. The full range of long variable will not fit in the integer variable, this cause data will be lost, this type of conversation is called explicit conversion. Then we can say the explicit conversion is not safe, the following result me occur.
  •  Risk of data loss 
  •  Throw error 
  •  No error but loss of data 
  •  Cast operators needed for Type casting. 
       
long b = 10000000000000;
int a = (int)b;


Boxing : When a value type is converted to reference type , the process is called  boxing and reverse process is called unboxing.

C # define a list of inversion method for conversion to a particular type, these are
* ToBoolean: To convert into Boolean type, that is true or false.  

  string str = "1";
  bool a = Convert.ToBoolean("1");

*ToByte : Convert into byte type or binary type.
 
  string str = "1";
  byte a = Convert.ToByte("1");

*ToChar : To convert into character type .
 
 string str = "1";
 char a = Convert.ToChar("1");

* ToDateTime :To convert into date time .
 
  string str = "1";
   DateTime a = Convert.ToDateTime("1");

* ToDouble : To convert into double type.


  string str = "1";
  double a = Convert.ToDouble("1");

* Toint16 / 32 / 64 : To convert into integer long type depending upon the data length. 
  
  string str = "1";
   int a = Convert.ToInt16("1");
* ToSingle : To convert into the single type date to string to convert into the string type.  
 
  string str = "1";
   Single a = Convert.ToSingle("1");
Conversion Type : Conversion Type are two types.


Boxing : Boxing is a feature of of.Net architecture which can be useful during the conversion. 
Boxing actually convert from value type to reference type. It is implicit conversion. Which a object is 
boxed, memory is allocated on the heap for the new object, name the values related variable to the 
actual object variable. For example I am declaring a integer type I, I am a sign it to a value hundred, 
now I am declaring an object type variable o. Now I am writing, o=I. Now the conversion has done 
and the value of a is assigned to the object o. 

int I = 100;
object o;
o = I;

Unboxing : Unboxing is a technique just reverse boxing , which converts reference type to
value type. It is an explicit conversion, which means data can be lost during conversion. When 
an hour is done, value from the object is copied to a variable which is reference type.
object o;
int i = (int)o;

What is a variable? variable storage location what does application store data and read when required.
Variable has a symbolic name and some types of data stored into it. The variable have a capacity,
quantity for storing the data. 

Integral : Integral is a term who is represented whole number. If you're right 12 it is a present a 
whole number 

Sign : Sign means means positive or negative numbers. Define variable means positive or negative 
number can be defined and stood in it. For example I can assign -12 to assign variable. But not 12 
unsigned variable. 

Here are the data types that C# supports 

Value types 
1) Simple -signed integral sbyte / short / int / long
2) Unsigned integral byte / unshort / uint /ulong
3) Unicode : char
4) IEEE standard double / float
5) Boolean : bull 
6) Enum type : any user defined type of data structure which can be used for data
 manipulation purpose. 
 7)Struct type data can be defined by user data manipulation. 

Reference type 
1) class type 
  • object 
  • string 
  • user defined 

2) Interface :User define type
3) Array type : Signed & multi dimensional
 
  Here is some top topic get it to the variable asked by the interviewer during the interview. 

1)  String and string , what is the difference between them? 

String is used for calling string class method , string is a variable type.  


        string a="hello";
        string b = String.Concat(a, "world");
        Response.Write(b);
    //hellow world  

2) Swap two variable without using the third variable  

      int a, b;
            a = 10;
            b = 20;
           a = a + b;
           b = a - b;
          a = a - b;
//a=20
//b=10

3)Convert.ToString and ToString who is handle the null and which throw exception ?


string a=null;
string b=Convert.ToString(a);
string c = a.ToString();

Convert.ToString handle null. If there is a null value in a variable Convert.ToString string handle 
smartly. And it is a type safe conversion process. Tostring is a process, which cannot handle null 
and throw null reference exception if null . 

4) Another very common practice during the entire conversion is TryParse. These methods parse 
string to integer value. This method has different implementation, depending upon the usage. 
If we pass string which cannot be converted into integer, the method will throw exception.



string input = "100";
int output = int.Parse(input);
Response.Write(output);
//output :100

string input = "hellow";
int output = int.Parse(input);
Response.Write(output);
//output :error ,Input string was not in a correct format.


5) Another type of implementation this method is out number. After conversion the method return in 
a variable true or false. If the conversion is successful then the method return true, if the method 
and successful , return false.  

string input = "100";
int output;
bool result = int.TryParse(input, out output);
if (result == true)
{
       Response.Write(output);
}
Output :
100






















Tuesday, 23 January 2018

002 C# Introduction

C # tutorial introduction 
C # is and types safe environment for better programming , developed by Microsoft as a part of
.Net framework. C# was developed by Anders Hejlsberg for Microsoft .Net Framework. It was later approved 
by ECMS and ISO. C Sharp is more type safe then C ++. We can build software like 
  • XML web service
  • Client server application 
  • Database application 
  • Web application 
  • Console application 
  • WCF application 
  • WPF applications and many more. 

.Net Framework is a managed type safe environment for software development and execution of the
 software. It allocate memory and grant permission for execution of the software. .Net Framework 
also support cross language compatibility. .Net component can communicate with each other even 
if component has written in different language. This type of communication is safe got by CTS common 
type specification.  C# also do automatic memory management and garbage collection.
.Net Framework consists of 4 languages. Among these 4, C# is the most Preferred language
 among the developers, for its beauty and simplicity and also easy to learn. C# is very powerful 
but simple programming language for building interoperable, scalable, robust application. Web service 
is easy to build C # and can we consume Web service from any platform. WCF Service also can be
consumed by any platform in the world. 

C # is object oriented language , features of OOPS supported
  • Class 
  • Object 
  • Inheritance 
  • Interface 
  • Polymorphism 
  • Data encapsulation 
  • Data Hiding 

Here is the list of component of .Net framework 
  • Common language specification 
  • Common language runtime 
  • .Net Framework class library 
  • Common type system 
  • Assemblies 
  • Windows forms 
  • ASP.NET 
  • Windows Communication Foundation 
  • Windows presentation Foundation 
  • Language integrated query 
  • Windows workflow Foundation. 

Before we go to the above following points, you should consider some topic of .Net Framework also

 Microsoft intermediate language(MSIL) :  Microsoft intermediate language also called intermediate 
language. While compiling a  program source code, Microsoft convert to a intermediate code. This 
intermediate code also includes instruction for loading storing information also.

Just in time compiler : A compiler which convert the intermediate language to machine language is 
called just in time compiler. This two step process, fast the source code is converted to intermediate 
language, then this intermediate language is converted to machine code. In the first step the source 
code is convert it to a byte code. This is called common language run time or intermediate language.
 In the second step the intermediate language is converted to machine instruction bye just in time 
compiler. 

Common type specification : Common type specification is a standard to represent specific 
type of value in the memory. Program written in different language can communicate with 
each other with standard with this stand. Example a type defined, a set of value define, 
now they can communicate with each other. Let the type defined as integer, they can 
communicate with each other and add, sum operation can be done. 

.Net class library : .Net class library is a collection of classes an interface and objects
 which provides the manage type safe development. .Net classes support inheritance which 
is base class and inherited class. Dot Net base class for safe development. Namespace is a
 is logical grouping of classes, we use those namespace only which class is
 required for the development , system is the base class which is required for any development. 
Because all preliminary functions and services are available in the System class. 
System.Data is a class which is child class of system, all data related services are incorporated 
in the System.Data class. We can do data access insert, update ,delete function and services are 
available in the system the data class. 

Here are some usable classes of .Net framework. 

System : This class is the root of all classes and all service preliminary stay in this classes. 
The preliminary data type and this are available in the system class. 

System.collection : This namespace is for memory management related to 
collections. The collections are array, array list, stack ,queue ,list, dictionary object 

System.Data : This namespace content class and services which are useful for data access and 
data manipulation. For example if we want to insert update or delete data, we need to add 
system.data namespace in our application. 

System.Data.oledb : This namespace are required to Oledb data. For example we can 
data handle with Microsoft access and excel with this namespace.

System.Data.SQLclient : Microsoft SQL server is a well-known database and is widely used. 
We can do data manipulation and access data with the help of this class. 

System.IO : File management such as read write edit file is very common for software developer, 
reading writing and editing file can be handled with the help of System.IO class. Every necessary 
service related to file management are available in this namespace. 

System.Math : Common mathematical functions and related service are available in this namespace. 
Example Sum,delete, random number are available in this namespace. 

System.Drawing : This is the namespace used for graphics in.Net framework. For example if i want to 
draw a line , I would use system to System.Drawing. Very simple an easy way to design and graphic 
object. 

System.Threading: .Net is a smart framework, operated on Windows platform, Windows 
operating system , .Net Framework both support multi threading process, the namespace help to 
develop the engineer multi threading applications with the help of this namespace. 

Assembly : Assembly is it self describing collection of program which help.Net to run smoothly.
 An assembly manifest is a part of assembly which store assembly name, version other
information about the assembly. Security instruction permission required also store in assembly 
manifest. Some other assembly, related information and there details are stored in the Assembly 
manifest. 

Satellite is a single application application, depending upon the call, resource file 
compile into the satellite assembly. Satellite assembly detect the user culture and load the 
corresponding string from assembly during run time . 

Windows form applications : A general purpose application for client server application, generally 
an application connected with a database for input and output purpose. In this application a graphical 
format, where user input is data is called win Windows form .

ASP.NET : An application which run on web web platform, for example www, http, https platform. 
Maybe it will be a client server application, maybe it is an method exposed to Web. 
That is web service. Web service development and consume also a part of ASP.NET. 

WCF : Windows Communication Foundation is an Technology which can communicate author 
platform through a channel. Specific data contract, data member , interface are required for 
communication through WCF channel. 

Language integrated query : It is a good features recent .Net framework , that is database query 
can be written in front end source code. The most popular implementation of the language integrated 
query is with entity framework, Microsoft Enterprise practice library.

Here is some more topics
Manage code : Any code written by .Net language within the .Net Framework is call manage 
code. C#, VB.Net and other .Net language are example of manage code. .Net Framework 
familiar with this languages and compiler compile this with manage code execution. 

Unmanaged code : Any code written by and which does not supported by .Net compiler is called 
unmanaged code. Its means, any language out of .Net Framework languages quotes are 
unmanaged..Net Framework does not know these languages and have no control over the
application written by this languages. 

Here are the example of manage and unmanaged code 

Manage code : C ,C plus plus, Window 32 API component 
Unmanaged code : VB.Net, C Sharp, G sharp, Js script


বাঙালির বেড়ানো সেরা চারটি ঠিকানা

  বাঙালি মানে ঘোড়া পাগল | দু একদিন ছুটি পেলো মানে বাঙালি চলল ঘুরতে | সে সমুদ্রই হোক , পাহাড়ি হোক বা নদী হোক। বাঙালির ...