Chapter 20. C# Language Reference
The following table describes the syntax of various C# language elements. The left column shows the syntax for each element, and the right column includes one or more examples.
Arrays | ||
type [*] + |
byte[ ] arr1 = new byte[10]; int[ ] arr2 = {0, 1, 2}; ([*] is the set: [ ] [,] [,,] etc.) | |
Attributes | ||
[[ |
[assembly:CLSCompliant(false)] [WebMethod(true, Description="My web method")] | |
Break statement | ||
break; |
break; | |
Checked/unchecked | ||
checked ( |
// throws exception short x = 32767; int i = checked( (short) ++x ); // silently overflows to -32768 short y = 32767; int j = unchecked( (short) ++y ); | |
checked |
// throws exception public short foo( ) { short y = 32767; checked { return ++y; } } // silently overflows public short bar( ) { short y = 32767; unchecked { return ++y; } } | |
Class declaration | ||
|
public class MyClass : Base, IFoo { // ... } | |
Constant declaration | ||
const |
const int xyzzy = 42; | |
Constant fields | ||
|
Get C# in a Nutshell, Second Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.