X hits on this document

944 views

0 shares

0 downloads

0 comments

259 / 396

C# LANGUAGE SPECIFICATION

static void Main(string[] args) { int max = int.Parse(args[0]); int count = Count(max); Console.WriteLine("Found {0} primes between 1 and {1}", count, max); } }

Note that the syntax for accessing elements of the BitArray is precisely the same as for a bool[].

The following example shows a 26 10 grid class that has an indexer with two parameters. The first parameter is required to be an upper- or lowercase letter in the range A–Z, and the second is required to be an integer in the range 0–9.

using System;

class Grid { const int NumRows = 26; const int NumCols = 10;

int[,] cells = new int[NumRows, NumCols];

public int this[char c, int col] { get { c = Char.ToUpper(c); if (c < 'A' || c > 'Z') { throw new ArgumentException(); } if (col < 0 || col >= NumCols) { throw new IndexOutOfRangeException(); } return cells[c - 'A', col]; }

set { c = Char.ToUpper(c); if (c < 'A' || c > 'Z') { throw new ArgumentException(); } if (col < 0 || col >= NumCols) { throw new IndexOutOfRangeException(); } cells[c - 'A', col] = value; } } }

10.8.1 Indexer overloading

The indexer overload resolution rules are described in §‎7.4.2.

10.9 Operators

An operator is a member that defines the meaning of an expression operator that can be applied to instances of the class. Operators are declared using operator-declarations:

operator-declaration: attributesopt   operator-modifiers   operator-declarator   operator-body

246Copyright Microsoft Corporation 1999-2003. All Rights Reserved.

Document info
Document views944
Page views944
Page last viewedThu Dec 08 02:46:02 UTC 2016
Pages396
Paragraphs9401
Words133190

Comments