Monday 10 March 2014

How to create a window application.Features on VS in this app.

Create a windows application by selecting File->new ->Project then project type Visual C# itself as console application Then in templates select windows application instead of console application.Create in same location as console application  ie.. (C:\BegVCSharp\Chapter2). with default name consoleapplication1.After clicking ok you can view an empty window form.Move mouse pointer on toolbar on left side of screen,double click on button option to add button to form.
Double click on button added to window form to display C# code.Modify it to -

private void button1_Click(object sender,EventArgs e)
{

MessageBox.Show("The first window app");
}

Run the application.
Click button when running to see message dialog box.
Exit clicking x.   
Features of VS
Here when double clicked on button on toolbar,VS knew that you wanted to write code to execute on click on button by user.
Also without code we can resize,minimize  and move around windows form and button.
UI ie, user interface building blocks are on toolbar to perform different functions like button option.
A properties window to make changes like for button option text changed to click me or which is currently set to button1.Other changes can be made are color changing,size changing etc..

Friday 7 March 2014

How to create a console application.Explain solution explorer,Properties window,Error list window functions.

Console applications
Create a new console application project by selecting File->New->Project or by pressing key shortcut or by clicking on corresponding icon in the toolbar.
Select visual C# in project types,console applications in templates,change location and other settings as they are.
Click on button.
Once project is initialized add following lines of code to the file displayed in main window.

namespace ConsoleApplication1
{
    class Program
    {
        static void main(string[] args)
        {
        Console.WriteLine("The first app beggining in c# programming!");
        Console.ReadKey();
        }
        }
}
Select debugg->start menu item or press a keyboard shortcut or a toolbar icon.You will see result in few minutes.
The first app beggining in c# programming!
Press a key to exit the application .
The console application will terminate as soon as they finish execution,ie, you don't get a chance to see result.To get around here code is told to wait for a key press before terminating.You will see this technique  used in many examples.

Solution explorer
This shows files in ConsoleApplication1.project created here.The code added file here is program.cs,It is shown along with another code file assemblyInfo.cs and a resource.cs file.
Remember all C# files have a .cs file extension .
Function done here is renaming file,deleting them from your project.Other types file are resource files such as bitmap images and sound files not c# codes here.
Reference entry contains list of .net libraries used in your project.

Properties window
It shows additional information about whatever you select in the window above.Changes made in this window will affect the code directly.

Error list window
It displays error when error exist in the code.Like missing of semicolon etc..The error shown is double clickedthen cursor will jump to the error in source code.Here you can fix it quickly.Also can see red wavy lines at position of errors in code.Error is shown by line number.If line numbers are not displayed in VS editor ,turn it on through Tools->options menu item ->Text Editor->General here tick auto list members

Wednesday 5 March 2014

What is asp.net?

It is part of the .net  framework.
Active Server Pages(ASP.NET)
It is a programming framework used to create web applications where web pages can be viewed by any browser.It is dynamically generating web content by .net framework.This section of .net framework called as asp.net(ie,Active Server Pages.NET).

Compare C++ and C#.What is C#.Explain variables and expressions in C#.Role of namespace in C#.

compare C# and C++-It is an evolution of C and C++ languages and has been created by Microsoft specially to work with .net platform.C# is able to make use of every feature that .net

framework code library has to offer compared to visual basic.Developing applications using C# is simpler than C++ because the syntax is simpler.Need to write more

codes in C# to carry same task than in C++,but will get benefit that code is more robust and debugging is simpler.

What is C#?
It is an evolution of C and C++ languages and has been created by Microsoft specially to work with .net platform.C# is able to make use of every feature that .net
framework code library has to offer compared to visual basic.Developing applications using C# is simpler than C++ because the syntax is simpler.Need to write more
codes in C# to carry same task than in C++,but will get benefit that code is more robust and debugging is simpler.C# is madeup of a series of statements,each of which is terminated with a semicolon.C# is block structured language ,meaning that all statements are part of a block of code.These blocks are delimited with braces({ and}) may contain any number of statements or none at all.
A simple block of C#
{
stmt;
}

Blocks may contain other blocks.
{
stmt;
    {
    stmt;
    }
stmt;
}
Comments when added allows you to add descriptive text to your code.Comments can be given in 4 ways in C3.Marker given at beginning and end of a comment or give marker then everything on rest of line is a comment.You can use single line comments with two or three symbols at start.

/*This is a comment*/
//This is a comment
///This a a comment

C# is case sensitive.
Console.WriteLine("The first app in C #");
This is the correct code
VS suggest you commands that you might use when you try to enter code.
Any keyword that starts with a # is a preproccessor directive.
All C# code has a cs.file extension.

Variables and expressions in C#

If computer programs are performing operations on data.Then this implies that you need some way of storing that data and some method to manipulate it.These two functions are performed by variables and expressions.

Variables in C#

variable naming rules
You cannot choose any set of characters as variable name.The first character must be either a letter,underscore(_) or at the rate aymbol(@),seqeuent characters may be letters,underscore or numbers.Since C# is case-sensitive you can have multiple variables whose names differ only in case.
example
myvariable
Myvariable
myVariable

Naming convention
Naming conventions in .net framework is of 2 types-PascalCase and camelCase.Thet both specify that each word in a name should be in lowecase ,except for its first letter.In camelcase casing addition rule is that first word should start with a lowercase.
camelCase variable names-
age
firstName
timeOfDeath
PascalCase variable names-
Age
LastName
WinterOfDiscontent

Declaration and initialization of variable
Variable is declared using type and variable name.
example
int age;
Multiple variables can be declared at same time by seperating it with commas.
example
int age,weight;
Variables must be intitalized before using them
example
int age=15;
It is initialization of variable age with 15
Variables can be initialized and declared at same time.
int age=15;
Also initialization,declaration,multiple variables at same time
int age=15;weight=40;

Use of variable
It store data in memory ie,consider variable has box,memory as shelf,data as thing stored in box of shelf.As things can be looked at or taken out same way data can be looked at or taken out from variable.As boxes can be different shape for holding different things same way variable can be in different types for holding different data.Firstly declare variable before using it as storage units ie,assiging a name and type,otherwise compiler show it as error.
Number is stored in memory as series of zero and one.ie,a variable with 2 bits can store only 4 numbers -
0= 00
1= 01
2= 10
3= 11
A variable with 3 bit can store 7 numbers only.

Types of variable
Listing types of variable as in .net framework library
Type     Alias for
sbyte     System.SByte
byte    System.Byte
short    System.Int16
ushort    System.UInt16
int    System.Int32
uint    System.UInt32
long    System.Int64
ulong    System.UInt64
float    System.Single
double    System.Double
decimal    System.Decimal
char    System.Char
bool    System.Boolean
string    System.String

Write a console application in C# showing declaration of two variables,assigning them values and then outputing these values.
static void main(string args)
{
int myinteger;
int mystring;
myinteger=17;
mystring="    \"myinteger\"  is ";
Console.WriteLine("{0},{1}",mystring,myinteger);
Console.ReadKey();
}
Execute the code
Output
"myinteger" is 17
Description of code-The code declaring two variables -
int myinteger;
string mystring;
Here variable name is myinteger with type int.And variable name is mystring with type string.
The code assigning values-
myinteger=17;
mystring="    \"myinteger\"  is";
There are certain problems like using double quotation mark inside the string ie,"integer" into string-  " \"myinteger\" is".
Here a sequence \" is used to escape a double quotation mark.Otherwise comipler error is shown.Escape sequence are of different types.

Escape sequences used in string literal
escape sequence         character produced
\'               single quotation mark
\''            double quotation mark
\\            backslash
\0            null
\a            alert(cause a beep)
\b             backspace
\f            float
\n            form feed
\n             new line
\r            carriage return
\t            horizontal tab
\v            vertical tab


string verbatim
It is used to show all characters inside double quotation mark is included in th string including end of line character and characters that would otherwise need escaping.
example
@"verbatim string literal."
Here fixed values are assigned to variables myinteger and mystring  using assignment operator =.
Console.WriteLine("{0}{1}",mystring,myinteger);
Here within brackets you have a string and a list of variables.Each set of curly brackets in string is a placeholder that will contain contents of one of variables in list.Each placeholder is represented as an integer enclosed in curly brackets.The integers start at 0 and increment by 1,total number of placeholder should match number of variables specified.In ouput placeholder is replaced by value of variable.
Console.ReadKey();
It pauses code execution until you press a key.

Expression
To manipulate variables we use expressions.Operands when used with operators create an expression.
Operators
It can be classified into
*)unary operator-Which act on single operand.
*)binary operator-Which act on two operands.
*)trenary operator-Which act on three operands.
Operator used with numeric types(integer and floating point).
operator    category    expression        result
+        binary        var1=var2+var3;        var1 is assigned value that is sum of var2 and var3.
-        binary        var1=var2-var3;        var1 is assigned value that is value of var3 subtracted from var2.
*        binary        var1=var2*var3;        var1 is assigned value that is product of var2 and var3.
/        binary        var1=var2/var3;        var1 is assigned value that is value of var2 divided by var2.
%        binary         var1=var2%var3;        var1 is assigned value that is remainder when var2 divided by var2.
+        unary        var1=+var2;        var1 is assigned value of var2
-        unary        var1=-var2        var1 is assigned value of var2 multiplied by -1.
++        unary        var1=++var2;        var1 is assigned value of var2+1
--        unary        var1=--var2;        var1 is assigned value of var2-1
++        unary        var1=var2++;        var1 is assigned value of var2.Then var2 is incremented by 1.
--        unary        var1=var2--;        var1 is assigned value of var2.Then var2 is decremented by 1.
Operator used with string.
+        binary         var1=var2+var3;        var1 is assigned value that is concatenation of two strings stored in var2 and var3.

Write a program to print a string and two numbers,then some calculations.
(*)Create a new console application.
(*)Add the code.
static void Main(string[] args)
{
    double firstNumber,secondNumber;
    string userName;
    Console.WriteLine("Enter your name:");
    userName=Console.ReadLine();
    Console.WriteLine("Welcome {0}",userName!);
    Console.WriteLine("Now give me a number:");
    firstNumber=Convert.ToDouble(Console.ReadLine());
    Console.WriteLine("Now give me another number:");
    secondNumber=Convert.ToDouble(Console.ReadLine());
    Console.WriteLine("Sum of {0} and {1} is {2}.",firstNumber,secondNumber,firstNumber+secondNumber);
    Console.WriteLine("Subraction of {0} from {1} is {2}.",secondNumber,firstNumber,firstNumber-secondNumber);
    Console.WriteLine("Product of {0} and {1} is {2}.",firstNumber,secondNumber,firstNumber*secondNumber);
    Console.WriteLine("Result of dividing {0} by {1} is {2}.",firstNumber,secondNumber,firstNumber/secondNumber);
    Console.WriteLine("Remainder after dividing {0} by {1} and is {2}.",firstNumber,secondNumber,firstNumber%secondNumber);
    Console.ReadKey();
}
(*)Execute code.
display of output
Enter your name:
(*)Enter your name and press enter.
display of output
Enter your name:
keerthi
Welcome keerthi!
Now give me a number:
(*)Enter a number,press enter,then another number,then enter again.
display of output
Enter your name:
keerthi
Welcome keerthi!
Now give me a number:
32.76
Now give me another number:
19.43
Sum of 32.76 and 19.43 is 52.19
Subraction of 32.76 from 19.43 is 13.33
Product of 32.76 and 19.43 is 63.5268
Result of dividing 32.76 by 19.43 is 1.68605249613999
Remainder after dividing 32.76 by 19.43 is 13.33

Two concepts used in this program
User input-It use the syntax Console.ReadLine();
Type conversion-Use the command Convert.ToDouble() on string obtained by Console.ReadLine() to convert string into a double type.
You assign this number to firstNumber variable
firstNumber=Convert.ToDouble(Console.ReadLine());

Assignment operators
Operator    Category    Expression    Result
=        binary        var1=var2;    var1 is assigned value of var2.
+=        binary        var1+=var2;    var1 is assigned value that is sum of var1 and var2.
-=        binary        var1-=var2;    var1 is assigned value that is value of var2 subtracted from value of var1.
*=        binary        var1*=var2;    var1 is assigned value that is product of var1 and var2.
/=        binary        var1/=var2;    var1 is assigned value that is result of dividing var1 by var2.
%=        binary        var1%=var2;    var1 is assigned value that is remainder when var1 is divided by var2.
Operator precedence
When expression is evaluated,each operator is processed in sequence.Not evaluating operators from left to right.
(ex1)var1=var2+var3;
Here + operator acts before = operator.
(ex2)var1=var2+var3*var4;
Here * operator acts first,followed by + operator,finally by = operator.
(ex3)var1=(var2+var3)*var4;
Here paranthesis is evaluated first.
(ex4)*,/ with equal precedence are evaluated from left to right.
precedence    Operators
highest        ++,-- used as prefix,+,- unary
        *,/,%
        +,-
        =,*=,/=,%=,+=,-=
lowest        ++,-- used as suffix
   
Namespaces-Namespaces are containers  for categorizing application code items which is provided by .net framework .Keyword namespace can be used to explicity define namespace for a block of code..C# code by default is contained in global namespace.
Items in one namespace are accessible by other namespace by refering them by name,for that names must be qualified.Qualified names means it should contain all hierarchical informations.Qualified names use period characters(.)between namespace levels while refering.
Example-
namespace LevelOne
    {
        //code in LevelOne namespace
        //name "NameOne" defined
    }
    //code in global namespace
This code defines one namespace LevelOne and a name in this namespace.
DEfined name in code is refered from code inside namespace by name NameOne.
Defined name in code is refered from code inside namespace by name LevelOne.NameOne.
Nested namespace-Within a namespace you can define another namespace.Nested namespace are also refered using periods to classify each level.
Example-
namespace LevelOne
    {
        //code in LevelOne namespace
        namespace LevelTwo
            {
                //code in LevelOne.LevelTwo namespace
                //name "NameTwo" defined
             }
    }
//code in global namespace
Same name defined in difeerent namespaces
Example
namespace LevelOne
{
    //name "NameThree" defined
    namespace LevelTwo
    {
        //name "NameThree" defined
    }
}
Here name NameThree is defined in LevelOne and LevelTwo namespaces.Here same NameThree is refered by names LevelOne.NameThree and LevelOne.LevelTwo.NameThree independently.
using statement in namespace
To simplify access to name defined in a namespace using statement is used.
Example
namespace LevelOne
{
    using LevelTwo;
    namespace LevelTwo
        {
        //name NameTwo defined
        }
}
Here code in LevelOne namespace can now refer to LevelTwo.NameTwo by simply using NameTwo.This can cause clashes if identical name used in different namespaces.
So here alias for a namespace is provide for using statement.
Example
namespace LevelOne
{
    using LT=LevelTwo;
    //name NameThree defined
    namespace LevelTwo
        {
        //name NameThree defined
        }
}
Here code in LevelOne namespace can now refer to LevelOne.NameThree by simply using NameThree.And code in LevelOne namespace can now refer to LevelOne.LevelTwo.NameThree by simply using LT.NameThree.
Example
namespace LevelOne
{
    using LT=LevelTwo;
    //name NameThree defined
    namespace LevelTwo
        {
        //name NameThree defined
        }
}
In preceding code global namespace can't use LT.NameThree. Here code in global namespace and LevelOne namespace can use LT.NameThree.
Exanple-

using LT=LevelOne.LevelTwo;
namespace LevelOne
{
    //name NameThree defined
    namespace LevelTwo
        {
        //name NameThree defined
        }
}


























   

























    

























































 








































































What type of applications can you write with C#.

You know .net framework has no restriction on types of applications,so since C# uses .net framework it has no restriction too.Common application types are windows

application,web applications and web services.

windows application-These are applications having familiar windows look and feel.It is made by windows forms module of .net framework.(windows forms module is a

library of controls susch as buttons,toolbars,menus etc.. which is used to build a windows user interface(UI)).

Web applications-These applications are web pages which can be viewed by any browser.It is dynamically generating web content by .net framework.This section of .net

framework called as asp.net(ie,Active Server Pages.NET).

Web services-These are distributed applications,here data are exchanged virtually over internet with no restriction in language or system it resides.

ADO.NET-All These applications require database access achieved by ADO.NET(Active Data Pages.NET)of .net framework.
Tools used for creating network components,outputting graphics,performing mathematical tasks etc by all applications as per need.

Tuesday 4 March 2014

How C# is executed?



C # is executed when converted into a language understood by target operating system.This code is called native code.This compilation is a two stage process.When code using .net framework is compiled first,it is converted into (microsoft intermediate language code)MSIL.This comiplation is done by VS.Just In Time compiler compiles MSIL into native code.Here MSIL is independent of machine,OS,CPU.

Explain visual studio with features.

It is the environment which support many languages like c#,c++,visual basic etc. and with ease .net features can be integrated into your code.
The code created will be entirely C# but will use .net framework and you can make use of additional tools in VS when necessary.

Main features of VS is -

Main window contain a start page by default when VS is started.It is the place where all codes will be displayed.

Toolbars is above the main window.It is pops up when mouse mouse over it.Its function range from saving and loading files to building and running projects to dubbing projects.

Server explorer is selectable via View->server explorer from menu option.It provide access to data sources,server settings,services etc.

Solution explorer is selectable via View->solution explorer from menu option.
It displays various view of projects in a solution ie,what files they contain and what is contained in those files.

Properties window is selectable via View->properties window from menu option.It provide detailed view of contents in a project and allow to perform additional configuration of individual elements.
Error list window is selectable via View->Error list menu option.It displays error,warning and other information related to projects.It updates continuously,although some information will appear only when a project is compiled.

How to write applications using .net framework.


Writing application means writing code on any language(like C#,C++,VB,J# etc,,) that support .net framework using .net code library.

Explain .net framework.



It is a software framework.It is developed by microsoft.It runs on microsoft windows operating system.It was released on 2002.It has library of codes which consist of different modules which can be used from any language(like C++,C#,VB,J SCRIPT etc) to create applications(like WEB,WINDOWS,CONSOLE,WEB SERVICES etc) without any restriction.You can use portions of it depending on results you want to achieve.