13.07.2015 Views

C# Language Specification - Willy .Net

C# Language Specification - Willy .Net

C# Language Specification - Willy .Net

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Chapter 8 <strong>Language</strong> Overview# of arguments: 0# of arguments: 1args[0] = 1# of arguments: 2args[0] = 1args[1] = 2# of arguments: 3args[0] = 1args[1] = 2args[2] = 3# of arguments: 4args[0] = 1args[1] = 2args[2] = 3args[3] = 4Most of the examples presented in this introduction use the WriteLine method of the Console class. Theargument substitution behavior of this method, as exhibited in the exampleint a = 1, b = 2;Console.WriteLine("a = {0}, b = {1}", a, b);is accomplished using a parameter array. The WriteLine method provides several overloaded methods forthe common cases in which a small number of arguments are passed, and one method that uses a parameterarray.namespace System{public class Console}{}public static void WriteLine(string s) {…}public static void WriteLine(string s, object a) {…}public static void WriteLine(string s, object a, object b) {…}…public static void WriteLine(string s, params object[] args) {…}8.4 Automatic memory managementManual memory management requires developers to manage the allocation and de-allocation of blocks ofmemory. Manual memory management can be both time-consuming and difficult. In <strong>C#</strong>, automatic memorymanagement is provided so that developers are freed from this burdensome task. In the vast majority ofcases, automatic memory management increases code quality and enhances developer productivity withoutnegatively impacting either expressiveness or performance.The exampleusing System;public class Stack{private Node first = null;public bool Empty {get {return (first == null);}}public object Pop() {if (first == null)throw new Exception("Can't Pop from an empty Stack.");else {object temp = first.Value;first = first.Next;return temp;}}25

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!