reference variables

8
Object Oriented Programming BY: IRFAN U. MEMON B.E (SOFTWARE ENGINEERING) MEHRAN UET. JAMSHORO

Upload: irfan-memon

Post on 27-Sep-2015

213 views

Category:

Documents


0 download

DESCRIPTION

Reference and value types

TRANSCRIPT

Object Oriented Programming

Object Oriented ProgrammingBy: Irfan U. MemonB.E (Software engineering)Mehran UET. JamshoroReference VariablesParametrized Methods.Value ParametersReference Parameter

OutlinesHeap and Stack

Data Types: Value Types and Reference TypesValue Typesvariables of value types directly contain their data.All intrinsic data types ( int, long, float etc)What happens when we assign one variable to an other.

Reference TypesVariables of reference types store references to their data.variables can reference the same object. Reference variables act differently than do variables of a value typeOperations on one variable can affect the object referenced by the other variableKeywords to declare reference type:class, interface, delegate.Building house1 = new Building();Building house2 = house1;

5Methods.Methods are subroutines that manipulate the data defined by the class.provide access to that dataDifferent parts of the program interacts with class through it methods.well-written C# code, each method performs only one task.Syntax of Method.access-modifier ret-type name(parameter-list) {// body of method}6Return from a method.There are two conditions that cause a method to returnWhen the methods closing curly brace is encounteredWhen a return statement is executedThere are two forms of returnOne for use in void methods (those that do not return a value)One for returning values7Using parameters It is possible to pass one or more values to a method when the method is called.A value passed to a method is called an argument.the variable that receives the argument is called a formal parameter Parameters are declared inside the parentheses.The parameter declaration syntax is the same as that used for variablesThe scope of a parameter is the body of its method.acts like any other local variable besides its special task.

8