C# Programming Language Part 1



 C# Language

 C# is a Modern Programming Language

Using C# we can build software applications

C# is an Object-oriented language which gives a clear structure to programs and allows Code to be reused. it's used in Gaming, websites, VB, Database applications, web, mobile, and desktop applications.

C# is strongly typed language. C# type is divided into two types - built-in and custom types.

C# Language

*Value and Reference Types*

   A value type variable contains the actual data within its own memory allocation.

                  value types derived from System.value type. 

                 Two Categories of value type Structs and enum.

  Reference Types is a reference to a location where the Data is stored. 

                  Ex. class, array, interface, delegate and event 

A null value is assigned to a reference type by default.


*Structs*

A struct type is a value type typically used to encapsulate a group of similar variables.
and it can Declare      Constructors,  Constants,  fields,  methods,  properties,  indexers, operators, and nested types.
Ex.
using System;  
  namespace StructSample  
{  
    // Book struct  
    public struct Book  
    {  
        public string Title;  
        public string Author;  
        public decimal Price;  
        public short Year;  
    }  
  
  class Program  
    {  
        static void Main(string[] args)  
        {  
            Console.WriteLine("Struct Sample!");  
  
            // Create a Book object  
            Book myBook = new Book();  
            myBook.Title = "Simplified C#";  
            myBook.Author = "Mahesh Chand";  
            myBook.Price = 45.95M;  
            myBook.Year = 2017;  
  
            Console.WriteLine($"Book {myBook.Title} was written by {myBook.Author}" +  
               $" in {myBook.Year}. Price is {myBook.Price}");  
  
            Console.ReadKey();  
        }          
    }  
}  

*Enums*

Enums in C# represents a set of Constant as integral values.
For Ex.  Week,  Points- X, Y  
Public enum Weekdays {Sun, Mon, Tue, Wed, Thurs, Fri, Sat} 


*Properties*

A property is like a combination of a variable and a method, and it has two methods a Get and a Set Method
.the Get method returns the value of the variable name.
.the set method assigns a value to the name variable.

* Array *
The array is used to store multiple values in a single variable, use [] square bracket o define array

*Variables*

Variables are Containers for storing data values.
 C# there are different types of variables 
  • Int – stores integers
  • Double-store floating point numbers, 
  • Char- store single characters A, B.
  • String – stores text, such as “hello world”.
  • Bool -  store values with two states: true or false
Type Conversion Methods

It is also possible to convert data types explicitly by using built-in methods, such as Convert.ToBoolean, convert. ToDouble, Convert.ToString, Convert.ToInt32 (int) and Convert.ToInt64 (long):

*String *

The string is used to store a text 
 C# is actually an object, which contains properties and methods that can perform certain operations on strings.

IF…ELSE Condition
You can use these conditions to perform different actions for different decisions.
C# has the following conditional statements:
  • Use if to specify a block of code to be executed, if a specified condition is true
  • Use else to specify a block of code to be executed if the same condition is false
  • Use else if to specify a new condition to test, if the first condition is false
  • Use the switch to specify many alternative blocks of code to be executed


If you found this article useful, share it.*

MS SQL Server interview questions for developers ~ SoftCodeLearner

SoftCodeLearner: ASP.NET

BookStore ~ SoftCodeLearner

FACEBOOK


Join telegram group-https://t.me/softwareCodeLearner


No comments:

Post a Comment