Showing posts with label C#. Show all posts
Showing posts with label C#. Show all posts

3 Sept 2013

How to create variable in c#

A variable can be compared to a storage room, and is essential for the programmer. In C#, a variable is declared like this: 

<data type> <name>; 

An example could look like this: 

string name; 

That's the most basic version. Usually, you wish to assign a visibility to the variable, and perhaps assign a value to it at the same time. It can be done like this: 

<visibility> <data type> <name> = <value>; 

And with an example:
private string name = "John Doe";
The visibility part is explained elsewhere in this tutorial, so let's concentrate on the variable part. We will jump straight to an example of actually using a couple of them:
using System;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            string firstName = "John";
            string lastName = "Doe";

            Console.WriteLine("Name: " + firstName + " " + lastName);

            Console.WriteLine("Please enter a new first name:");
            firstName = Console.ReadLine();

            Console.WriteLine("New name: " + firstName + " " + lastName);

            Console.ReadLine();
        }
    }
}
Okay, a lot of this has already been explained, so we will jump directly to the interesting part. First of all, we declare a couple of variables of the string type. A string simply contains text, as you can see, since we give them a value straight away. Next, we output a line of text to the console, where we use the two variables. The string is made up by using the + characters to "collect" the different parts. 

Next, we urge the user to enter a new first name, and then we use the ReadLine() method to read the user input from the console and into the firstName variable. Once the user presses the Enter key, the new first name is assigned to the variable, and in the next line we output the name presentation again, to show the change. We have just used our first variable and the single most important feature of a variable: The ability to change its value at runtime. 

27 Aug 2013

What is C#?

C# is a modern, general-purpose object oriented programming language developed by Microsoft and approved by Ecma and 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 to be used on different computer platforms and architectures.
The following reasons make C# a widely used professional language:

  • Modern, general purpose programming language
  • Object oriented.
  • Component oriented.
  • Easy to learn.
  • Structured language.
  • It produces efficient programs.
  • It can be compiled on a variety of computer platforms.
  • Part of .Net Framework.

Strong Programming Features of C#

Although C# constructs closely follows traditional high level languages C and C++ and being an object oriented programming language, it has strong resemblance with Java, it has numerous strong programming features that make it endearing to multitude of programmers worldwide.
Following is the list of few important features:

  • Boolean Conditions
  • Automatic Garbage Collection
  • Standard Library
  • Assembly Versioning
  • Properties and Events
  • Delegates and Events Management
  • Easy to use Generics
  • Indexers
  • Conditional Compilation
  • Simple Multithreading
  • LINQ and Lambda Expressions
  • Integration with Windows

How to export GridView data to excel in asp.net in C#.

 protected void btnexport_Click(object sender, EventArgs e)
 {
        string attachment = "attachment;         filename=RepurchaseRpt".xls";
        Response.Clear();
        Response.AddHeader("content-disposition", attachment);
        Response.Charset = "";
        Response.ContentType = "application/vnd.xls";
        System.IO.StringWriter stringWrite = new System.IO.StringWriter();
        System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);
        GridView1.RenderControl(htmlWrite);
        Response.Write(stringWrite.ToString());
        Response.End();
    }
    public override void VerifyRenderingInServerForm(Control control)
    {
    }

How to Create WEBSITE DESIGN

Way2finder Technologies is a web design studio that offers corporate web design and custom web design. Our website designers offer cheap w...