About Course

C# is a simple, modern, general-purpose, object-oriented programming language developed by Microsoft within its .NET initiative led by Anders Hejlsberg. This tutorial will teach you basic C# programming and will also take you through various advanced concepts related to C# programming language.

C# programming is very much based on C and C++ programming languages, so if you have a basic understanding of C or C++ programming, then it will be fun to learn C#.

About Author

This guy is perfect to teach you, how to use C# programming to Develop mobile apps development and to use C# to solve real world problems. he has an great Knowledge in C# programming. he design many projects including someĀ mobile apps, desktop apps etc.

C# Overview.

C# is a modern, general-purpose, object-oriented programming language developed by Microsoft and approved by European Computer Manufacturers Association (ECMA) and International Standards Organization (ISO).

C# was developed by Anders Hejlsberg and his team during the development of .Net Framework.

C# is designed for Common Language Infrastructure (CLI), which consists of the executable code and runtime environment that allows use of various high-level languages on different computer platforms and architectures.

The following reasons make C# a widely used professional language:

  • It is a modern, general-purpose programming language
  • It is object oriented.
  • It is component oriented.
  • It is easy to learn.
  • It is a structured language.
  • It produces efficient programs.
  • It can be compiled on a variety of computer platforms.
  • It is a part of .Net Framework.
Window Application Development 65%
Mobile Application Development 89%
For student Learning 90%
For Web Development 60%
Ranking in Programming World 96%
Popularity In Programming World 90%
Recommended to Your 80%
C# Discussion Boards

36 Comments

  • Haider Shah Posted January 19, 2019 8:10 pm

    Dear Omer! How can i use ZenBarcode(QrCode) in Crystal Report? Thanks in Advance Haider Shah

  • D’al Mismeaik Posted December 10, 2018 2:40 pm

    Many code smells, did you make that stink on purpose?

  • Haya Posted June 7, 2017 11:52 am

    Sardar Omar, look at this example, plz,

    using System;
    
    namespace Addition
    {
        class Program
        {
            public int add(int x, int y)
            {
                return x + y;
            }
    
            static void Main(string[] args)
            {
                int val1, val2;
                Program ADD = new Program();
                Console.WriteLine("Enter first value: ");
                val1 = Convert.ToInt32(Console.ReadLine());
    
                Console.WriteLine("Enter Second Number: ");
                val2 = Convert.ToInt32(Console.ReadLine());
    
                Console.WriteLine("{0} + {1} = {2}: ", val1, val1, ADD.add(val1, val2));
    
                Console.ReadKey();
    
            }
        }
    }
    

    I am beginner in C# programming. in the above example, I just want to take user input in the same line, and also print the output in same line. thanks in advanced.

    • Sardar Omar Posted June 8, 2017 7:59 am

      Good Day Haya – Look at this example:

      using System;
      
      namespace Addition
      {
          class Program
          {
              public int add(int x, int y)
              {
                  return x + y;
              }
      
              static void Main(string[] args)
              {
                  int val1, val2;
                  Program ADD = new Program();
                  Console.Write("Enter first value: ");
                  val1 = Convert.ToInt32(Console.ReadLine());
      
                  Console.Write("Enter Second Number: ");
                  val2 = Convert.ToInt32(Console.ReadLine());
      
                  Console.WriteLine("{0} + {1} = {2}: ", val1, val1, ADD.add(val1, val2));
      
                  Console.ReadKey();
      
              }
          }
      }
      

      You need to change just console.WriteLine() to console.Write()
      Enjoy your learning with InfoBrother:

  • Nesha Posted May 17, 2017 10:49 am

    Hi Infobrother, I did a lot of searching, but find the appropriate answer of my Question. so please could you explain, What is the difference between “polymorphism” and “inheritance”. ??

    thank you.

    • Sardar Omar Posted May 17, 2017 11:56 am

      HI Nesha,
      Did you read these topic in Our C# Tutorials?? i think you don’t.
      so read this tutorial OOP Introduction first to clear your concept about OOP. and read Polymorphism and Inheritance Tutorial.

  • Jimmy Posted May 1, 2017 7:18 am

    Hi InfoBrother, its Jimmy from India, I’m learning C#, and I am new in programming world with “NO” experience. i am learning about constructors and i’m Quite confused what’s the difference between methods and constructor. because i am following some books, YouTube Google, and Obviously InfoBrother.com too. i found almost same programming example of constructor in all over where even in your website. so i don’t know how to differentiate them. should i use constructor or should i use method. because its seem same in coding. i would appreciate your ideas. and honestly, it’s interesting to learn coding through your website. because its really conceptual and easy to understand each and every topic.

    thank you in Advance.
    cheers:

    • Jessa Rose Posted May 1, 2017 3:23 pm

      Hi Jimmy thanks for your good response. and enjoy your learning with infoBrother.

      • A constructor only works when you create a new Object of a class. This is the very first method to run on an Object, it has to run, and it runs exactly once.
      • A method on an Object can be called anywhere between zero times to infinite times on an Object once it is created.
      • A constructor is run implicitly. When a new Object of a class is created, it runs automatically. A method is run explicitly. It has to be called either from some outside source or from a method -or a constructor- in the class.
      • A constructor is intended to be used for wiring. In the constructor, you want to avoid doing actual work. You basically prepare the class to be used. A method is intended to do actual work.
      • Jimmy Posted May 2, 2017 10:51 am

        Thank you Jessa Rose, could you please explain the words Implicitly and Explicitly. well I know the meanings, but I don’t know, what does it mean in C#??

        • Jessa Rose Posted May 2, 2017 11:35 am

          When We create an Object with new Keyword, constructor automatically runs, mean Implicitly. And When we want to invoke a method, we clearly tell the Object to run that method, mean Explicitly.

  • Andrew Posted April 29, 2017 4:23 am

    Hi There, Well what is the default access Modifiers For Class and Members in C#?

    • Sardar Omar Posted April 29, 2017 11:29 am

      Hi Andrew, The Default Access Modifiers at Namespace level are Internal: and at Class Level are Private:. Consider the Following Example:

      namespace program
      {
          class info
          {
              int x; 
              void display(){}
          }
      }

      is Equal to…

      namespace program
      {
          Internal class info
          {
              Private int x; 
              Private void display(){}
          }
      }
    • Aisha Khan Posted April 30, 2017 3:10 am
                           | Default   | Permitted declared accessibilities
      ------------------------------------------------------------------
      namespace            | public    | none (always implicitly public)
      
      enum                 | public    | none (always implicitly public)
      
      interface            | internal  | public, internal
      
      class                | internal  | public, internal
      
      struct               | internal  | public, internal
      
      delegate             | internal  | public, internal
      
  • Maria Posted March 26, 2017 6:43 pm

    Hi this is Maria from Delhi (india). i was writing some code using switch statement like this way:

    switch (numbers)
    {
       case 1:
       case 2:
                 //some code:
                 break;
       case 3:
       case 4: 
                 //some code:
                 break; 
        //and so on:
    }  

    i know the above code is good, and will work too. but i want to write this code in this way:

    switch (number )
    {
       case 1, case 2:
                     //some code:
                     break;
       case 3, case 4:
                    //some code: 
                    break; 
         //and so on
    }

    but this method is not working, so please can you show me some methods like this, in sense of short cut.
    thankx.

    • Brian Bondy Posted March 26, 2017 9:51 pm

      Maria, your first method is good, but there is no syntax in C# or C++ for your second method that you mentioned.
      however if you have a big ranges, you can use just the series of if-else statements:

    • Sardar Omar Posted March 27, 2017 11:59 am

      Yes Maria, Brian Bondy is right, there is no way to use your second method in C#. but still you can mix your both methods in a syntactically way like this:

      switch (number )
      {
         case 1: case 2:
                       //some code:
                       break;
         case 3: case 4:
                      //some code: 
                      break; 
           //and so on
      }

      thank you for your comments, enjoy your learning with infoBrother.

      • Maria Posted March 27, 2017 1:15 pm

        Got it, so i need to replace colon with comma, that’s it??

        • Sardar Omar Posted March 27, 2017 4:21 pm

          Yep exactly, that’s it…

          • Maria Posted March 27, 2017 7:23 pm

            Ok Thank You Sardar.
            thanks for your support, Good luck

  • Jasmeen Posted March 24, 2017 9:15 am

    HI Infobrother how you doing, I am Jasmeen from Lahore. I am in beginner level in C#. I came across from a source code, and I found something like this:

    for ( ; ; )
    {
        //some code
    }

    so I just want to know, what exactly is this, as per me, there are 3 statement in for loop, but here, no statement. what is this??
    thanks in advance.

    • Sardar Omar Posted March 24, 2017 11:24 am

      Hi Jasmeen, welcome to C# world. it’s an infinite loop with no condition, lemme explain this to you.
      in General we write for-loop something like this:

      for(int i = 0; i < 10; i++)
      {   
         //some code;
      }

      in above for loop there are three parameters or statements, these statements are optional, The basic syntax of for-loop is:

      for(initial;  condition; operation)

      if we don't declare any conditions for the loop, the default condition of for-loop kicks in that is true so the loop condition will be always true, and will continue the loop, till you terminate the program yourself.

  • Usman Posted March 16, 2017 3:17 pm

    Hi buddies,

    if(number == null)
    {
       //return nothing;
    }
    else 
    {
       return number;
    }
    

    how exactly I can write the same code using ?: or ?? Operators:
    thank you.

    • Sardar Omar Posted March 16, 2017 5:53 pm

      These Operators are not designed for control flow, it’s only designed for conditional assignment.

      The expression:
      a ? b : c evaluates to b if a is true and evaluates to c if a is false.
      b ?? c evaluates to b if b is not null and evaluates to c if b is null.
      and if you write return a ? b : c; or return b ?? c: they will always return somethings.

      if you need to control the flow of your program, use a control structure such as if/else.

      • Sana Posted March 17, 2017 11:01 am
        1. The conditional Operator ( ? ) returns one of the two values depending on the value of a Boolean expression.
        2. The null-coalescing operator ( ?? ) Is used to define a default value for a nullable values types as well as reference types. it returns the left-hand operand if it is not null, else if will returns the right operand.
        • Usman Posted March 18, 2017 2:06 pm

          Thank you Sardar Omar, and sana for your kind response. BTW you have awesome collection of tutorials. really easy and conceptual for beginners. any body can start from scratch easily using this site.. keep it up infobrother team. (y)

  • Pretty Posted March 12, 2017 3:48 am

    Hello Infobrother,
    is there any or Operator in C#?? like I want to do this,

    if (first_condition or second_condition == true)
    {
         //if condition body;
    }

    how how to do this in C#??

    • Jessa Rose Posted March 12, 2017 11:03 am

      C# Support two Boolean “or” Operator.
      The single bar “|” and the double-bar “||“.

      The difference is that, the single bar “|” always checks both the left and right conditions, while the double bar “||” only checks the right-side condition if it’s necessary (if the left side evaluates to false).

      so you can use this syntax:

      if(first_conditon || second_condition == true)
      {
         //body
      }

      • Pretty Posted March 12, 2017 1:13 pm

        Thank you Jessa. I understand now.

  • Jea Posted March 11, 2017 3:02 pm

    Hi there, we in C++ we can define a constant like #define var1 = 9; so how can I do this in C# Programming ??

    • Sardar Omar Posted March 11, 2017 4:07 pm

      Hi Jea. in C# we can do this using “Const” Keyword:
      Example: public const int var1 = 9;

      You need to define this variable somewhere in class. and the usage would be classname.var1;

  • George Posted March 11, 2017 11:56 am

    What does the @ symbol before a variable name mean in C#?

    • Sardar Omar Posted March 11, 2017 12:07 pm

      We can’t use keyword as an identifier or variable name. in this case we can use “@” this symbol to reserved an keyword as an identifier.
      Example:

      int class;   //not valid, because class is an keyword:
      int @class; //Now its become variable:

      • George Posted March 11, 2017 12:56 pm

        Ok, Thank you so much. this tutorials is really good and easy to understand. keep it up.

  • Monty Posted March 6, 2017 9:47 am

    I am doing some classification and I am not sure:
    INT is a primitive datatype with keyword "int"

    But I can use Int16,Int32 or Int64 – I know C# has its own names for them. But are those data types as well or it is still INT? And mainly, can we say “short” is a datatype or INT16 is a datatype?

    Thanks šŸ™‚

    • Sana Posted March 7, 2017 10:50 am

      In C#, the following examples are always true:

      short == Int16;
      ushort== UInt16;
      int   == Int32;
      uint  == UInt32;
      long  == Int64;
      ulong == UInt64;

      Both versions are data types. All of the above are integers of various lengths and signed-ness.
      The main difference between the two versions (as far as I know) is what colour they are highlighted as in Visual Studio.

  • jonii Posted March 4, 2017 10:41 am

    I like your way to explain this topic. http://www.infobrother.com/Tutorial/CSharp/Csharp-Environment-Setup Impressive:
    thank for such a easy and awesome tutorials.
    good luck.

Ask Question?

Leave a Reply to Sana Cancel reply

Your email address will not be published. Required fields are marked *

Please wait...

Subscribe to our newsletter

Want to be notified when our New Course and Article is published? Enter your email address and name below to be the first to know.