Skip to main content

Variables

Variables
You may have been using variables and constants in since your 3rd grade. In any programming language same concept of variables is used which covers more than half of your code. Now is you have worked in C++ or Java or Python or any other programming language you may have used variables. If you are new to programming and you have started with C# its totally OK because you don't need any degree to learn programming.
Now what are the variables, to be precise variables are the empty shells which can be filled to their limit and their value can variate with the passage of time as required and manipulated on desire. 
Their are few types of variables:
Types Examples
Integral Types stype, byte, short, ushort, int, unit, long, ulong and char
Floating Point Types Floating and Double
Decimal Types Decimal
Boolean Types True or False value, as assigned
Nullable Types Nullable Data Types

Declaration
Moving on we have some rules for declaring a variable. 


  • A variable must start with an alphabet or "-".
  • Good programming practice is to chose a noun as a variable name
  • There should be no empty space in between a variable name
  • Variables are case sensitive
  • Appropriate Data must be used
  • If you want to declare a Nullable variable ? must be used at the end of the data type.

  • Lets see an example

    namespace Variables
    {
        class Program
        {
            static void Main(string[] args)
            {//integer
                int data1;
                //character
                char data2';
                //float
                float data3;
                //double
                double data4;
                //Nullable
                int? data5;
                //Boolean
                Boolean data6;
                //decimal
                decimal data7;
            }
        }
    }
    

    Initializing a variable

    To initialize a variable an assignment operator is used. Usually in common language we name the assignment as equal sign. Most importantly one should know what is actually initializing a variable, it's nothing but first time assignment of a variable. As C# is a purely object oriented language so we will talk in context of classes. We can initialize the variables when they are declared (but finals are initialized when declared strictly), we can also initialize the variables at run time.

    Lets see an example

    namespace Variables
    {
        class Program
        {
            static void Main(string[] args)
            {//integer
               int data1=0;
               //character
               char data2='0';
               //float
               float data3=(float)0.0;
               //double
               double data4=0.0;
               //Nullable
               int? data5=null;
               //Boolean
               Boolean data6=false;
               //decimal
               decimal data7=3.3m;
            }     } }
    
    

    Share your views comment below.






    Comments

    Popular posts from this blog

    Software Engineering Week 1

    Software Engineering  Software engineering is an engineering discipline that concerns to all aspects of software development and software production. Mentioned above is the typical definition of software engineering that should develop a mind setup of a student who is wiling to learn development of software. Now when we talk about development of software, its life cycle pops into our minds which is being taught in almost every educational institution.  SDLC SDLC (Software Development Life Cycle) is the basic and core concept of Software Engineering. SDLC include few steps that should be followed strictly in order to develop a software. Most common terms used for those steps are: Analysis Designing Coding Testing Deployment and Maintenance   These steps are followed to develop a software. Firstly we should know what is a computer software. A computer software is nothing but computer program and associated documentation. Difference betw...

    Generations of Computer Part 2

    Third Generation Computer The period of third generation was from 1965-1971. These computers were faster, smaller,generate less heat, consumed less space and less power and more reliable than first and second generation computers but these computers were still costly.The computers of third generation used Integrated Circuits (ICs) in place of transistors. A single IC has many transistors, resistors, and capacitors along with the associated circuitry. This development made computers smarter, reliable, and efficient. In this generation remote processing, time-sharing, multi programming operating system were used. High-level languages like  PASCAL PL/1, BASIC, ALGOL-68  were used during this generation. Some of the third generation computers are as follow: IBM-360 series Honeywell-6000 series PDP (Personal Data Processor) IBM-370/168 TDC-316 Fourth Generation Computer The fourth generation was invented in 1971 and is still being used.Most of the p...

    Generations of Computer Part 1

    Hello azumavenger  and  welcome to my blog. Today we are going to talk about the computer generations Computer Machine and Their Generations As we all know Computer is an electronic machine which solve different calculations precisely, accurately, in short span of time and more efficiently. Now the question is that why was such thing invented in first place. Humans are more intelligent than computers, they can make decisions and can conquer many things on the base of feelings then why was computer needed. The answer is simple to save human from labor work. Computers were nothing like what they are today The PC's to be precise Personal Computers we use today were not this efficient and cool back in John Mauchly's days. They were big, they consumed more power and were not easy to use. Diving deep, computer machines evolved from different versions to become what they are today, It started from ENIAC and is still being updated. Actually around 4 generations h...