21 October 2013

Numbers pyramid in c#.net

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

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            int number_of_layer = 7, Space, Number;
            Console.WriteLine("Print paramid");
            for (int i = 1; i <= number_of_layer; i++) // Total number of layer for pramid
            {
                for (Space = 1; Space <= (number_of_layer - i); Space++)  // Loop For Space
                    Console.Write(" ");
                for (Number = 1; Number <= i; Number++) //increase the value
                    Console.Write(Number);
                for (Number = (i - 1); Number >= 1; Number--)  //decrease the value
                    Console.Write(Number);
                Console.WriteLine();
              
            }
            Console.ReadLine();
        }
    }
}




Introduction to Ajax


AJAX is not a technology but it is a group of technologies (as Javascript, CSS, XHTML, DOM etc). We can also say it is a combination of client side technologies that provides asynchronous communication b\w user interface and web server so that partial page rendering occurs instead of complete page post back. It is platform independent means AJAX is a cross platform technology that can be used an any Operating system since it is based an XML & Javascript. It also supports open source implementation of other technology. It partially render the page to the server instead of complete page postback.We use AJAX for developing faster better and more interactive web applications.AJAX use HTTP request b\w web server & browser.

Ajax Features

1.     Ajax minimize round trips to the server.
2.     It is language independent means we can use ajax in every language
3.     Ajax is platform independent.
4.     Rendering of webpage is faster.
5.     Reduce consumption of server resources.

Ajax Drawback

Response Time in AJAX based development we should care of response time b\w client & server because it gets normally delayed. AJAX is based on Java Script and different browser implement Javascript different way. Hence here may be a problems on different browser.
Example :Uploading of file in gmail & do working in message body box.

Script Manager

It manages all ASP.Net AJAX controls on the web page. It renders the AJAX library to the browser and supports partial page rendering. It also manage partial page uploades and provide access to web service method. Without script manager we can't use AJAX controls on the web page.
 
What is ajax
·         AJAX is Asynchronous JavaScript And XML.
·         The XmlHttpRequest is an actual object which works behind the scene.
·         Ajax implementation uses JavaScript functions to call methods from a webservice, webpage request in response to get response.
·         Response data is parsed using DOM.
·         Asynchronous data retrieval using XmlHttpRequest
 
 
Advantages of ajax
 
·         Reduce the traffic travels between the client and the server.
·         Response time is faster so increases performance and speed.
·         You can use JSON (JavaScript Object Notation) which is alternative to XML. JSON is key value pair and works like an array.
·         You can use Firefox browser with an add-on called as Firebug to debug all Ajax calls.
·         Ready Open source JavaScript libraries available for use – JQuery, Prototype, Scriptaculous, etc..
·         AJAX communicates over HTTP Protocol.
 
Disadvantages of ajax
 
·         It can increase design and development time
·         More complex than building classic web application
·         Security is less in AJAX application as all files are downloaded at client side.
·         Search Engine like Google cannot index AJAX pages.
·         JavaScript disabled browsers cannot use the application.

·         Due to security constraints, you can only use it to access information from the host that served the initial page. If you need to display information from another server, it is not possible within the AJAX.

How to generate the Fabonacci Series in C#.Net


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

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            int a = -1;
            int b = 1;
            int x;
            Console.WriteLine("Enter the x value =");
            x = int.Parse(Console.ReadLine());
            for (int i = 0; i < x; i++)
            {
                int sum = b + a;
                a = b;
                b = sum;
                Console.WriteLine(sum);


            }
            Console.ReadLine();
        }
    }
}







AUTO INCREMENT


Syntax for SQL Server
The following SQL statement defines the "ID" column to be an auto-increment primary key field in the "Persons" table:
CREATE TABLE Persons
(
ID int IDENTITY(1,1) PRIMARY KEY,
LastName varchar(255) NOT NULL,
FirstName varchar(255),
Address varchar(255),
City varchar(255)
)
The MS SQL Server uses the IDENTITY keyword to perform an auto-increment feature.
In the example above, the starting value for IDENTITY is 1, and it will increment by 1 for each new record.
Tip: To specify that the "ID" column should start at value 10 and increment by 5, change it to IDENTITY(10,5).
To insert a new record into the "Persons" table, we will NOT have to specify a value for the "ID" column (a unique value will be added automatically):

INSERT INTO Persons (FirstName,LastName)
VALUES ('Lars','Monsen')

The SQL statement above would insert a new record into the "Persons" table. The "ID" column would be assigned a unique value. The "FirstName" column would be set to "Lars" and the "LastName" column would be set to "Monsen".

Given Number is Prime number or not in C#.Net



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

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            int count = 0;
            Console.WriteLine("Enter a value");
            int x = int.Parse(Console.ReadLine());

            int y = 2;
            if (y <= x / 2)
            {
                if (x % y == 0)
                {
                    count++;
                }
            }
            if (count == 0 && count != 1)
            {
                Console.WriteLine(x + " is Prime Number");
            }
            else
            {
                Console.WriteLine(x + " is not Prime Number");
            }
            Console.ReadLine();
        }
    }
}

Output