Skip to main content

Featured Post

How to use Tabs in ASP.NET CORE

I want to show Components in a tabs , so first of all create few components. In this project we have three components, First View Component  public class AllViewComponent : ViewComponent     {         private readonly UserManager<ApplicationUser> _userManager;         public AllViewComponent(UserManager<ApplicationUser> userManager)         {             _userManager = userManager;         }         public async Task<IViewComponentResult> InvokeAsync()         {             List<StudentViewModel> allUsers = new List<StudentViewModel>();             var items = await _userManager.Users.ToListAsync();             foreach (var item in items)             {                 allUsers.Add(new StudentViewModel {Id=item.Id, EnrollmentNo = item.EnrollmentNo, FatherName = item.FatherName, Name = item.Name, Age = item.Age, Birthdate = item.Birthdate, Address = item.Address, Gender = item.Gender, Email = item.Email });             }            

C# - Basic Syntax

C# supports object-oriented features like Class, Object, Encapsulation, Polymorphism, Data abstraction, Inheritance etc. In Object-Oriented Programming technology, we works on real time entity(known as object), these entity related to each other also communicate by message passing. If we discuss about class, a class consists of data member and member function (known as encapsulation). Using Object we can call method also initialize class data members. In later session we will discuss about object oriented features. In this article we will design basic structure of class and object.For example, let us consider a circle object. It has attributes like radius. Depending upon the design, it may need ways for accepting the values of this attribute, calculating area and display details.

Let us look at an implementation of a circle class and discuss C# basic syntax, on the basis of our observations in it:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace circle
{
    class circle_area
    {
         private static float pi = 3.14F;
         private int radius;
        // initialize datamember in the constructor.
         public circle_area(int radi)
         {
             radius = radi;

         }
        // calcuate area of the circle.
         public double getarea()
         {
             return pi * radius * radius;
         }

    }
    class Program
    {
        static void Main(string[] args)
        {
            circle_area ca = new circle_area(5);
            Console.WriteLine(Convert.ToString(ca.getarea()));
            Console.ReadKey();
        }
    }
}


When the above code is compiled and executed, it produces the following result:
circle area with 5 radius - output
The First line of the program define the system Namespace, a single program can hold multiple using statement. The System Namespace consists of many class like Console class. The Second line of the program hold NameSpace declaration, according to my previous article a single Namespace can contain multiple classes, in this program we have two class first one is circle_area and second one is program. In later session we will discuss, how a Namespace consists of another Namespace, deligates and structure. The third line of the program define class declaration, In this program we have two classes and each class hold at least single member function.


Comments in C#

Comments are used for designing user friendly program. Compilers ignore the comment entries. we can use single line as well as multi-line comments in the c# program The multi-line comments in C# programs start with /* and terminates with the characters */ as shown below:

/* Program define how to
calculate circle area with static keyword*/
Single-line comments are declared by double slash like //, according to above mentioned code, which is
// initialize Data Member in the constructor.

Data Member

It shows the properties of an object, suppose you have a object employee so create a class, which covers employee details like Employee_id, Employee_Name, etc. These properties known as data members. In this example we have two properties for circle class, these are pi and radius. Basically these variable are used for storing data.

Member Functions

It shows the behavior of the class, in which we can perform some action related to object properties. In this example we have one member function getarea(), which returns calculated area in double type.

Class and how to declare it:

Class is a user defined data type or you can say it is a composite data type. we have many definition of a class like "Class is a container of data member and member function" and second one is "class is a instance of a variable". 
Design a new class in c#- synatx of class
class class_name 
{
// Data member;
// Member function;    
}

Ok, Now understand what is in this program:
First start with main () method because its the entry point of the program. Here we have a object , which is created by new keyword. Also assign the instance name , which is ca. According to constructor theory, When we create a object ,constructor call automatically. Assign the Data Member by the constructor.  
 After assign the data member we can perform some operation on it. Now, we calculate area of the circle using getarea() method. This method is called from object ca.

Comments

Popular Post

Polynomial representation using Linked List for Data Structure in 'C'

Polynomial representation using Linked List The linked list can be used to represent a polynomial of any degree. Simply the information field is changed according to the number of variables used in the polynomial. If a single variable is used in the polynomial the information field of the node contains two parts: one for coefficient of variable and the other for degree of variable. Let us consider an example to represent a polynomial using linked list as follows: Polynomial:      3x 3 -4x 2 +2x-9 Linked List: In the above linked list, the external pointer ‘ROOT’ point to the first node of the linked list. The first node of the linked list contains the information about the variable with the highest degree. The first node points to the next node with next lowest degree of the variable. Representation of a polynomial using the linked list is beneficial when the operations on the polynomial like addition and subtractions are performed. The resulting polynomial can also

How to use Tabs in ASP.NET CORE

I want to show Components in a tabs , so first of all create few components. In this project we have three components, First View Component  public class AllViewComponent : ViewComponent     {         private readonly UserManager<ApplicationUser> _userManager;         public AllViewComponent(UserManager<ApplicationUser> userManager)         {             _userManager = userManager;         }         public async Task<IViewComponentResult> InvokeAsync()         {             List<StudentViewModel> allUsers = new List<StudentViewModel>();             var items = await _userManager.Users.ToListAsync();             foreach (var item in items)             {                 allUsers.Add(new StudentViewModel {Id=item.Id, EnrollmentNo = item.EnrollmentNo, FatherName = item.FatherName, Name = item.Name, Age = item.Age, Birthdate = item.Birthdate, Address = item.Address, Gender = item.Gender, Email = item.Email });             }            

Memory representation of Linked List Data Structures in C Language

                                 Memory representation of Linked List              In memory the linked list is stored in scattered cells (locations).The memory for each node is allocated dynamically means as and when required. So the Linked List can increase as per the user wish and the size is not fixed, it can vary.                Suppose first node of linked list is allocated with an address 1008. Its graphical representation looks like the figure shown below:       Suppose next node is allocated at an address 506, so the list becomes,   Suppose next node is allocated with an address with an address 10,s the list become, The other way to represent the linked list is as shown below:  In the above representation the data stored in the linked list is “INDIA”, the information part of each node contains one character. The external pointer root points to first node’s address 1005. The link part of the node containing information I contains 1007, the address of