Important Notes is C #

– // is called a single-line comment .

– /* Comment */ is multiple-line comments .

– A syntax error is caused when the compiler cannot recognize a statement.

– Every program should begin with one or more comments that describe the program’s purpose .

– Collectively, blank lines, space characters, new line characters and tab characters are known as whitespace .

– "The numbers entered are {0} and {1}", number1, number2 );

– Console.Write( "Please enter the first integer: " );

– firstNumber = Console.ReadLine();

– Follow the closing right brace (}) of the body of a method or class definition with a singlelinecomment.

This comment should indicate the method or class that the right brace terminates

– Every variable has a name, a type, a size and a value

– Console.WriteLine( number1 + " == " + number2 );

– Bohm and Jacopini’s work demonstrated that all programs could be written in terms ofonly three control structures, namely, the sequence structure, the selection structure andthe repetition structure.

– The if structure is called a single-selection structure because it selects or ignores a

single action (or a single group of actions). The if/else structure is called a double-selection

structure because it selects between two different actions (or groups of actions). The

switch structure is called a multiple-selection structure because it selects among many

different actions (or groups of actions).

– Many algorithms can be divided logically into three phases—an initialization phase that initializes

the program variables, a processing phase that inputs data values and adjusts program

variables accordingly and a termination phase that calculates and prints the results.

– preincrement : ++a

– postcrement : a++

– predecrement : –a

– postdecrement : a–

– MessageBox In C # : MessageBox.Show ( Message to Display, Title bas string, Dialog Button, Icon ) .

– Math.Pow( x, y ) calculates the value of x raised to the yth power .

– switch multiple-selection structure .

– String.Format( "{0:C}", amount ) and a newline character to position

to the next line. The call to method String.Format converts amount to a

string and formats this string so that it will display with two decimal places

Key Word

abstract

As

Base

Bool

Break

Byte

Case

catch

Char

checked

class

const

continue

Decimal

Default

delegate

do

double

Else

enum

Event

Explicit

Extern

False

finally

Fixed

Float

For

Foreach

Goto

If

Implicit

In

Int

Interface

Internal

Is

Lock

Long

Namespace

new

Null

Object

Operator

Out

Override

Params

Private

Protected

Public

Readonly

Ref

Return

Sbyte

Sealed

Short

Sizeof

Stackalloc

Static

String

Struct

Switch

This

Throw

True

Try

Typeof

uint

ulong

Unchecked

Unsafe

Ushort

Using

Virtual

Void

Volatile

while

– grade = Char.Parse( Console.ReadLine() );

– Console.WriteLine(

"\nTotals for each letter grade are:\nA: {0}" +

"\nB: {1}\nC: {2}\nD: {3}\nF: {4}", aCount, bCount,

cCount, dCount, fCount );

– do

{

statement

} while ( condition );

– relational operators >, <, >= and <= and the equality operators == and !=.

– The operators are && (conditional AND),& (logical AND), || (conditional OR), | (logical OR), ^ (logical exclusive OR or logicalXOR) and ! (logical NOT, also called logical negation) .

– In expressions using operator &&, if the separate conditions are independent of one another,make the condition most likely to be false the leftmost condition. In expressions using operator||, make the condition most likely to be true the leftmost condition. This use of shortcircuitevaluation can reduce a program’s execution time.

– A condition containing the logical exclusive OR (^) operator is true if and only if oneof its operands results in a true value and one results in a false value.

– ! (logical negation) operator to enable a programmer to "reverse" themeaning of a condition. Unlike the logical operators &&, &, ||, | and ^, which combinetwo conditions (binary operators) = if ( ! ( grade == sentinelValue ) )

– To connect control structuresin sequence to form structured programs, the exit point of one control structure is connectedto the entry point of the next control structure (i.e., the control structures are simplyplaced one after another in a program). We call this process "control-structure stacking." .

– Rules for Forming Structured Programs

1) Begin with the "simplest flowchart" .

2) Any rectangle (action) can be replaced by two rectangles (actions) in sequence. (stacking rule ) .

3) Any rectangle (action) can be replaced by any control structure (sequence, if, if/else,switch, while, do/while, for or foreach, as we will see in

Chapter 7, Arrays) (nesting rule ) .

4) Rules 2 and 3 may be applied as often as you like and in any order.

– Functions of Structured Programming :

• Sequence .

    – Already Sequined

• Selection .

    – if structure (single selection)

– if/else structure (double selection)

– switch structure (multiple selection)

• Repetition .

– while structure

– do/while structure

– for structure

– foreach structure (discussed in Chapter 7)

– Experience has shown that the best way to develop and maintain a large program is to construct it from small, simple pieces, or modules.

This technique is known as divide and conquer

– wideningconversion occurs when a type is converted to other types (usually types that can hold moredata) without losing data, and a narrowing conversion occurs when data may be lostthrough a conversion (usually to types that hold a smaller amount of data).

– int result = Square( ( int ) y );

– The actualcode for the classes is located in .dll files called assemblies.

– For an overview of the namespaces in the FCL,look up ".NET Framework, class library" in the help documentation.

– Defferince between .Net & C# AS LIKE : y3ny bezabt akenny b2olak ezzay tekteb fel word ( -> C#) .. wezzay testa7’dem el word 3shan tetba3 elly katabto (-> .Net)

– When an argument is passed by value, the called method receives a copy of the argument’s value.

– C# provides the ref and out keywords : for reference & value types .

– When an argument is passed using pass-by-reference, the caller gives the method theability to access and modify the caller’s original data directly

// Math Class Functions .

Namespace

Description

System

Contains essential classes and data types (such as int, double,char, etc.). Implicitly referenced by all C# programs.

System.Data

Contains classes that form ADO .NET, used for databaseaccess and manipulation.

System.Drawing

Contains classes used for drawing and graphics.

System.IO

Contains classes for the input and output of data, such as withfiles.

System.Threading

Contains classes for multithreading, used to run multiple partsof a program simultaneously.

System.Windows.Forms

Contains classes used to create graphical user interfaces.

System.Xml

Contains classes used to process XML data .

Type

Size in bits

Values

Standard

Bool

8

true or false

Char

16

‘\u0000’ to ‘\uFFFF’

(Unicode character set)

Byte

8

0 to 255

(unsigned)

sbyte

8

-128 to +127

Short

16

–32,768 to +32,767

Ushort

16

0 to 65,535

(unsigned)

Int

32

–2,147,483,648 to 2,147,483,647

Uint

32

0 to 4,294,967,295

(unsigned)

Long

64

–9,223,372,036,854,775,808 to

+9,223,372,036,854,775,807

Ulong

64

0 to 18,446,744,073,709,551,615

(unsigned)

Decimal

128

1.0 x 10-28 to 7.9 x 1028

float

32

±1.5 × 10-45 to ±3.4 × 1038

(IEEE 754 floating point)

Double

64

±5.0 × 10-324 to ±1.7 × 10308

(IEEE 754 floating point)

– to take a instance variable while you have the same name to a local variable write : this." Instance var. "

– It is important to note the difference between the "seventh element of the array" and "arrayelement seven." Array subscripts begin at 0, thus the "seventh element of the array" has asubscript of 6, while "array element seven" has a subscript of 7 and is actually the eighthelement of the array. This confusion is a source of "off-by-one" errors.

– bubble sort, because smaller values gradually "bubble" their way

to the top of the array (i.e., toward the first element) like air bubbles rising in water

(Quicksort) In this chapter, we discussed the sorting technique bubble sort. We now present the recursive sorting technique called Quicksort. The basic algorithm for a single-subscripted array of values is as follows:

a) Partitioning Step. Take the first element of the unsorted array and determine

its final locationin the sorted array (i.e., all values to the left of the element in the array are less than

the element, and all values to the right of the element in the array are greater than the element).

We now have one element in its proper location and two unsorted subarrays.

b) Recursive Step. Perform step 1 on each unsorted subarray.

Each time Step 1 is performed on a subarray, another element is placed in its final location of thesorted array, and two unsorted subarrays are created. When a subarray consists of one element, itmust be sorted; therefore, that element is in its final location.

The basic algorithm seems simple, but how do we determine the final position of the first elementof each subarray? Consider the following set of values (partitioningelement in bold—it will be placed in its final location in the sorted array):

37 2 6 4 89 8 10 12 68 45

a) Starting from the rightmost element of the array, compare each element to 37

until an element less than 37 is found, then swap 37 and that element. The first element less than 37 is 12, so 37 and 12 are swapped. The new array is

12 2 6 4 89 8 10 37 68 45 Element 12 is italicized to indicate that it was just swapped with 37.

b) Starting from the left of the array, but beginning with the element after 12,

compare each element to 37 until an element greater than 37 is found, then swap 37 and that element.

The first element greater than 37 is 89, so 37 and 89 are swapped. The new array is

12 2 6 4 37 8 10 89 68 45

c) Starting from the right, but beginning with the element before 89, compare

each elementto 37 until an element less than 37 is found, then swap 37 and that element. The first element less than 37 is 10, so 37 and 10 are swapped. The new array is :

12 2 6 4 10 8 37 89 68 45

d) Starting from the left, but beginning with the element after 10, compare each

element to 37 until an element greater than 37 is found, then swap 37 and that element. There are no more elements greater than 37, so when we compare 37 to itself, we know that 37 has been placed in its final location of the sorted array.

Once the partition has been applied to the previous array, there are two unsorted subarrays. The subarray with values less than 37 contains 12, 2, 6, 4, 10 and 8. The subarray with values greater than 37 contains 89, 68 and 45. The sort continues with both subarrays being partitioned in the same manneras the original array.

Using the preceding discussion, write recursive method QuickSort to sort a single-subscripted integer array. The method should receive as arguments an integer array, a starting subscript and an ending subscript. Method Partition should be called by QuickSort to perform the partitioning step.

Advertisements

One thought on “Important Notes is C #

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s