Friday, 20 January 2017

How to setup Angular2 Windows Local Machine

1 comment

Topics of Article:

1.Downloading npm and node.
2.creating new project in angular2
3.Installing dependencies for Angular2
4.Running Small application.

Angular 2 is the new Java script framework released by the Tech gaint Google after Angular js.There are some differences between Angular 1 and Angular2 versions.In Angular 2 google introduced a Component based development.I will discuss about those in other article now in this article i am going to explain about Angular 2 Setup in Local windows machine.

Now you can ask me a question We have more online quick start live coding Environments for Angular 2 why should i need to setup it on local.But it is not the place to develop real applications.You should develop in local and to develop you should learn.
Note: Example for live coding here..

Steps to Setup Angular2



Step1:
1.Download and install node and npm from here if you not installed yet.
2.Download node.js official site https://nodejs.org/en/download/.

Note: Node.js and npm are essential to modern web development with Angular and other platforms. Node powers client development and build tools. The npm package manager, itself a node application, installs JavaScript libraries.
3.After installing node.js on your system you can check it using command prompt using below command.
node -v
Here in my system i have the latest version 6.8.3 of node.

Updating npm:
Node comes with npm installed so you should have a version of npm. However, npm gets updated more frequently than Node does, so you'll want to make sure it's the latest version.
Note: Version should be higher than 2.1.8 to support  latest libraries installation.
npm install npm@latest -g
It updates npm to latest version.

Step 2:
1.Create a folder for angular project where ever you want in your machine.Ex:Angular2quickstart-master.
2.Download Angular2 QuickStartSeed into your project folder from here.
3.open your command prompt and navigate to your project folder for ex: Angular2quickstart-master i created.
Step 3:
1.Type Install npm command to install all node dependencies.

2.The dependency packages installed like below.



3.Type npm start and press enter to run the angular2 example in browser.
Step 4:
1.Then browser automatically opens it will shows welcome message like below.

Conclusion

In future articles i will explain how to setup angular2 in Visual studio also.To know more angular2 please subscribe to this blog subscribe. OR follow on Social networks for daily awesome updates[Facebook,twitter,google plus].

Tuesday, 3 January 2017

Learning Angular Js in ASP.NET MVC

Leave a Comment

Introduction

Angular Js is an open source framework developed by Tech giant Google.AngularJS is a structural framework for dynamic web apps. It lets you use HTML as your template language and lets you extend HTML's syntax to express your application's components clearly and succinctly. Angular's data binding and dependency injection eliminate much of the code you would otherwise have to write.

Angular supports the MVC based approach for developing Single page applications.It also support twoway data binding.

Here in this blog i am going to cover all angular js components(from data binding to expressions,controllers,services etc) with help of simple applications in step by step using ASP.NET MVC as a server side programming language.We will learn about angular js by going through below tutorials.


Angular tutorials start here

1.Introduction to angular js
2.How to setup Angular js in ASP.NET MVC
3.How to get Data from Database using Angular js in MVC 5 application
4.How to create a Login page using Angular JS
5.How to create a Registration form using Angular JS
6.how to get and display table data from database using angular
7.CRUD operations using angular js (Most viewed tutorial in this blog).
8.Implementing Cascading Dropdownlist
9.How to implement Angular UI Grid in ASP.NET MVC 5
10.How to implement Modal popup using Angular UI in ASP.NET MVC
11.Understanding routing in Angular JS
12.How to Implement Auto Complete Textbox using Angular js in MVC5
13.Implementing DatePicker using Angular UI in MVC5
14.How to integrate Google Maps in MVC 5 application
15.Implementing Star Rating using AngularJS
16.MultiBar Horizonthal Chart using Angular JS(nvd3.js)
17.Angular nvd3 Force Direction Graph in MVC5 application
18.Implementing Event Scheduling in Angular UI calendar part1
19.CRUD operations on Angular UI Calendar(Event Scheduling) part-2
20.Kendo Grid implementation using Angular
21.Tree View implementation in Angular JS
22.Integrating Angular Text Editor in ASP.NET MVC application
23.Google Organization Chart using Angular js

Conclusion

I hope this tutorial is understandable and useful for every reader.Please comment if you suggest any modification to improve the quality of article.If you are not subscribed to this blog subscribe.follow on Social networks for daily awesome updates[Facebook,twitter,google plus].

Sunday, 1 January 2017

Working with arrays in C Sharp Programming part-2

Leave a Comment
In previous tutorial i explained about What are arraya and Different types of arrays(Working with arrays in C Sharp Programming) in C Sharp Programming.In present tutorial i am going to explain about Array class,How we are going to use this array class and its method and properties in C Sharp programming.
Note: If you new to arrays please click on above link to know basics of arrays.

What is Array Class

Array class is the parent class of all arrays and it provides functionality for creating, manipulating, searching, and sorting arrays in .NET Framework.

The definition for array class is defined in System Namespace (arrays class definitions are imported using Using System namespace).It is the base class for arrays in C#. Array class is an abstract base class that means we cannot create an instance of the Array class.

Creating an Array Using array class

1.Array class provides the CreateInstance method to construct an array. The CreateInstance method takes first parameter as the type of items and second and third parameters are the dimension and their range. Once an array is created, we use SetValue method to add items to an array.
2.The following are different overriding methods for CreateInstance method.
public static Array CreateInstance(Type elementType, int length);        
public static Array CreateInstance(Type elementType, params int[] lengths);      
public static Array CreateInstance(Type elementType, params long[] lengths);     
public static Array CreateInstance(Type elementType, int length1, int length2);     
public static Array CreateInstance(Type elementType, int length1, int length2, int length3);
3.The following code snippet creates an array and adds three items to the array. As you can see the type of the array items is string and range is 3. You will get an error message if you try to add 4th item to the array.
Array stringArray = Array.CreateInstance(typeof(String), 3);
stringArray.SetValue("Mahesh Chand", 0);
stringArray.SetValue("Raj Kumar", 1);
stringArray.SetValue("Neel Beniwal", 2);
Note: Calling SetValue for existing value in array overrides the previous value in array.
4.To create an multi dimensional array we will use foreach loop as follows.
Array intArray3D = Array.CreateInstance(typeof(Int32), 2, 3, 4);
for (int i = intArray3D.GetLowerBound(0); i <= intArray3D.GetUpperBound(0); i++)
    for (int j = intArray3D.GetLowerBound(1); j <= intArray3D.GetUpperBound(1); j++)
        for (int k = intArray3D.GetLowerBound(2); k <= intArray3D.GetUpperBound(2); k++)
        {
            intArray3D.SetValue((i * 100) + (j * 10) + k, i, j, k);
        }
 
foreach (int ival in intArray3D)
{
    Console.WriteLine(ival);
}


Array Class Properties

IsFixedSize: Return a value indicating if an array has a fixed size or not.

IsReadOnly: Returns a value indicating if an array is read-only or not.

LongLength: Returns a 64-bit integer that represents total number of items in all the dimensions of an array.
Length: Returns a 32-bit integer that represents the total number of items in all the dimensions of an array.
Rank: Returns the number of dimensions of an array.
The following code snippet shows how we use array properties.
int[] intArray = new int[3] {0, 1, 2};
if(intArray.IsFixedSize)
{
    Console.WriteLine("Array is fixed size");
    Console.WriteLine("Size :" + intArray.Length.ToString());
    Console.WriteLine("Rank :" + intArray.Rank.ToString());
}

Searching for an Item in an Array

The BinarySearch static method of Array class can be used to search for an item in an array. This method uses the binary search algorithm to search for an item in array. The method takes at least two parameters. First parameter is the array in which you would like to search and the second parameter is an object that is the item you are looking for. If an item is found in the array, the method returns the index of that item (based on first item as 0th item). Otherwise method returns a negative value.
syntax:
public static int BinarySearch(Array array, object value);
Example for Binary search in array.
Array stringArray = Array.CreateInstance(typeof(String), 5);
stringArray.SetValue("Mahesh", 0);
stringArray.SetValue("Raj", 1);
stringArray.SetValue("Neel", 2);
stringArray.SetValue("Beniwal", 3);
stringArray.SetValue("Chand", 4);
 
// Find an item
object name = "Neel";
int nameIndex = Array.BinarySearch(stringArray, name);
if (nameIndex >= 0)
    Console.WriteLine("Item was at " + nameIndex.ToString() + "th position");
else
    Console.WriteLine("Item not found");


Note: But to perform search on array we must sort an array before searching.

Sorting Items in an Array

The Sort static method of the Array class can be used to sort array items. This method has many overloaded forms. The simplest form takes as a parameter the array you want to sort. Listing 5 uses the Sort method to sort array items. Using the Sort method, you can also sort a partial list of items.
Array stringArray = Array.CreateInstance(typeof(String), 5);
stringArray.SetValue("Mahesh", 0);
stringArray.SetValue("Raj", 1);
stringArray.SetValue("Neel", 2);
stringArray.SetValue("Beniwal", 3);
stringArray.SetValue("Chand", 4);
 
// Find an item
object name = "Neel";
int nameIndex = Array.BinarySearch(stringArray, name);
if (nameIndex >= 0)
    Console.WriteLine("Item was at " + nameIndex.ToString() + "th position");
else
    Console.WriteLine("Item not found");
 
Console.WriteLine();
 
Console.WriteLine("Original Array");
Console.WriteLine("---------------------");
foreach (string str in stringArray)
{
    Console.WriteLine(str);
}
 
Console.WriteLine();
Console.WriteLine("Sorted Array");
Console.WriteLine("---------------------");
Array.Sort(stringArray);
foreach (string str in stringArray)
{
    Console.WriteLine(str);
} 
Alternatively the Sort method takes starting index and number of items after that index. The following code snippet sorts 3 items starting at 2nd position.
Array.Sort(stringArray, 2, 3);

Getting and Setting Values of Array

The GetValue and SetValue methods of the Array class can be used to get and set values of an array's items. The code listed in Listing 4 creates a 2-dimensional array instance using the CreateInstance method. After that I use the SetValue method to add values to the array.
Array names = Array.CreateInstance(typeof(String), 2, 4);
names.SetValue("Rosy", 0, 0);
names.SetValue("Amy", 0, 1);
names.SetValue("Peter", 0, 2);
names.SetValue("Albert", 0, 3);
names.SetValue("Mel", 1, 0);
names.SetValue("Mongee", 1, 1);
names.SetValue("Luma", 1, 2);
names.SetValue("Lara", 1, 3);
int items1 = names.GetLength(0);
int items2 = names.GetLength(1);
for (int i = 0; i < items1; i++)
    for (int j = 0; j < items2; j++)
        Console.WriteLine(i.ToString() + "," + j.ToString() + ": " + names.GetValue(i, j));
In end of the program i got the values and names of array using GetValue method.

Reverse an array items

In similar to sort method we use Reverse method to reverse the array items.
Array.Reverse(stringArray);
//  Array.Sort(stringArray, 2, 3);
foreach (string str in stringArray)
{
    Console.WriteLine(str);
}

Clear items of array

The Clear static method of the Array class removes all items of an array and sets its length to zero. This method takes three parameters - first an array object, second starting index of the array and third is number of elements. The following code clears two elements from the array starting at index 1 (means second element of the array).
syntax:
Array.Clear(array name, startindex, endindex);
Note: Keep in mind, the Clear method does not delete items. Just clear the values of the items.

Get the size of an array

The GetLength method returns the number of items in an array. The GetLowerBound and GetUppperBound methods return the lower and upper bounds of an array respectively. All these three methods take at least a parameter, which is the index of the dimension of an array. The following code snippet uses all three methods.
Console.WriteLine(stringArray.GetLength(0).ToString());
Console.WriteLine(stringArray.GetLowerBound(0).ToString());
Console.WriteLine(stringArray.GetUpperBound(0).ToString()); 

Copying an array

The Copy static method of the Array class copies a section of an array to another array. The CopyTo method copies all the elements of an array to another one-dimension array. The code listed in Listing 9 copies contents of an integer array to an array of object types. 
Array oddArray = Array.CreateInstance(Type.GetType("System.Int32"), 5);
oddArray.SetValue(1, 0);
oddArray.SetValue(3, 1);
oddArray.SetValue(5, 2);
oddArray.SetValue(7, 3);
oddArray.SetValue(9, 4);
// Creates and initializes a new Array of type Object.
Array objArray = Array.CreateInstance(Type.GetType("System.Object"), 5);
Array.Copy(oddArray, oddArray.GetLowerBound(0), objArray, objArray.GetLowerBound(0), 4);
int items1 = objArray.GetUpperBound(0);
for (int i = 0; i < items1; i++)
    Console.WriteLine(objArray.GetValue(i).ToString());
You can even copy a part of an array to another array by passing the number of items and starting item in the Copy method. The following format copies a range of items from an Array starting at the specified source index and pastes them to another Array starting at the specified destination index.
public static void Copy(Array, int, Array, int, int);

Cloning an Array

Clone method creates a shallow copy of an array. A shallow copy of an Array copies only the elements of the Array, whether they are reference types or value types, but it does not copy the objects that the references refer to. The references in the new Array point to the same objects that the references in the original Array point to. The following code snippet creates a cloned copy of an array of strings.
string[] clonedArray = (string[])stringArray.Clone();
These are the main array methods that we daily use in C Sharp programming.

Conclusion

I hope this tutorial is understandable and useful for every reader.Please comment if you suggest any modification to improve the quality of article.If you are not subscribed to this blog subscribe.follow on Social networks for daily awesome updates[Facebook,twitter,google plus].