03.01.2015 Views

C# 5.0 Programmer's Reference

Visual Studio 2013 C# 5.0 Programmer's Reference

Visual Studio 2013 C# 5.0 Programmer's Reference

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.

Classes ❘ 271<br />

For more information on attributes, go to these web pages:<br />

➤➤<br />

➤➤<br />

Attributes (<strong>C#</strong> and <strong>C#</strong>) (msdn.microsoft.com/library/z0w1kczw.aspx)<br />

Attributes Tutorial (msdn.microsoft.com/library/aa288454.aspx)<br />

For a list of 578 attributes that you can use, go to Microsoft’s “Attribute Class” web page at<br />

msdn.microsoft.com/system.attribute.aspx and look at the “Inheritance Hierarchy” section<br />

at the bottom.<br />

accessibility<br />

If a class is declared directly within a namespace, its accessibility clause must be either public or<br />

internal. You can also omit accessibility, in which case the default is internal.<br />

If a class is declared inside a structure, its accessibility clause can be public, private, or<br />

internal. If the class is declared within a class, the clause can also take the values protected<br />

and protected internal.<br />

The following table summarizes the meanings of these values and when they are allowed.<br />

Keyword Allowed In Meaning<br />

public<br />

internal<br />

private<br />

protected<br />

protected internal<br />

namespace<br />

structure<br />

class<br />

namespace<br />

structure<br />

class<br />

structure<br />

class<br />

structure<br />

class<br />

structure<br />

class<br />

The class is visible to all code inside or outside of<br />

the class’s assembly.<br />

The class is visible only to code inside the<br />

class’s assembly.<br />

The class is visible only to code inside the<br />

containing namespace, structure, or class.<br />

The class is visible only to code inside the<br />

containing structure or class, or in a class derived<br />

from the containing class.<br />

Combines protected and internal.<br />

For example, the following code defines a Person class.<br />

namespace OrderProcessor<br />

{<br />

public class Person<br />

{<br />

www.it-ebooks.info

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

Saved successfully!

Ooh no, something went wrong!