O'Reilly logo

.NET Programming: A Practical Guide Using C# by Pradeep Tapadiya

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Attribute-Based Programming

It is often desirable to expose certain aspects of the code such as architectural constraints, behaviors, features, and so forth, in a nonprocedural way. You are already familiar with C++ and C# keywords such as public and private. These keywords further define the behavior of the class members by describing their accessibility to other classes. .NET lets you define additional aspects of a programming element, such as types and fields, by means of annotating the entity with attributes. The following code excerpt illustrates this idea:

// Project Attributes

[ObsoleteAttribute("Please don't use this method")]
public static int Add(int x, int y) {
  return x + y;
}

public static void Main() {
  int z = Add(10,20);
}

In ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required