C# Language & .NET Platform 9th Lecture Pavel Ježek pavel.jezek@d3s.mff.cuni.cz Some of the slides are based on University of Linz .NET presentations. © University of Linz, Institute for System Software, 2004 published under the Microsoft Curriculum License (http://www.msdnaa.net/curriculum/license_curriculum.aspx)
CLI Type System All types Value types Reference types Pointers (allocated in-place [with exceptions]) Reference types (allocated on managed heap) Pointers Structures Enumerations Classes (e.g. strings) Interfaces Arrays Delegates Simple types (Int32, Int64, Double, Boolean, Char, …) Nullables User defined structures
Visibility class private struct private Visibility modifiers: public Access is not restricted. protected Access is limited to the containing class or types derived from the containing class. internal Access is limited to the current assembly. protected internal Access is limited to the current assembly or types derived from the containing class. private Access is limited to the containing type. Default visibility in: enum public class private interface public struct private
CLI Type System All types Value types Reference types Pointers (allocated in-place [with exceptions]) Reference types (allocated on managed heap) Pointers Structures Enumerations Classes (e.g. strings) Interfaces Arrays Delegates Simple types (Int32, Int64, Double, Boolean, Char, …) Nullables User defined structures
Parameters - "call by value" value parameters (input parameters) void Inc(int x) {x = x + 1;} void f() { int val = 3; Inc(val); // val == 3 } - "call by value" - formal parameter is a copy of the actual parameter - actual parameter is an expression
Parameters - "call by value" value parameters (input parameters) void Inc(int x) {x = x + 1;} void f() { int val = 3; Inc(val); // val == 3 } - "call by value" - formal parameter is a copy of the actual parameter - actual parameter is an expression - "call by reference" - formal parameter is an alias for the actual parameter (address of actual parameter is passed) - actual parameter must be a variable ref parameters (transient parameters) void Inc(ref int x) { x = x + 1; } void f() { int val = 3; Inc(ref val); // val == 4 }