Presentation is loading. Please wait.

Presentation is loading. Please wait.

Indexer AKEEL AHMED.

Similar presentations


Presentation on theme: "Indexer AKEEL AHMED."— Presentation transcript:

1 Indexer AKEEL AHMED

2 Overview Indexers Enums Exception Handling What is Attribute?

3 Indexer Indexers allow your class to be used just like an array.
Indexer an object to be indexed in the same way as an array. Indexer modifier can be private, public, protected or internal. The return type can be any valid C# types. Indexers in C# must have at least one parameter. Else the compiler will generate a compilation error.

4 Indexer(Example)

5 Indexer(Example)

6 Enums Enums are known as named constants..
They are essentially unique types that allow you to assign symbolic names to integral values. Enums are strongly-typed constants that makes the code more readable and less prone to errors Default data type of an enum is an integer. If we assign an integer value to an enum variable then the next variable will contain a value just greater than 1 from the previous value.

7 Enums(Example)

8 Enums(Example) Assign value to enum member.

9 Enums(Example) Change the default type of enum.

10 Exception Handling NET provides a structured way of handling the runtime errors. Business logic and error handling code is separate. The errors that occur during the execution of a program are called the runtime errors or the exceptions. Exception handling mechanism provides a way to respond to the run time errors in the program by transferring control to special code called handler. Example (Division by 0, Stack overflow, invalid type casting)

11 Object-Oriented way of error handling
Classes to handle different types of errors. FileNotFoundException class to represent, if the file not found. IOException class to represent, if the file is already open. SecurityException class to represent, if the caller does not have permission to access the file. Easy to program and extend

12 try/catch Blocks When exceptions are thrown, you need to be able to handle them. This is done by implementing a try/catch block

13 Finally Blocks finally block will be executed before control leaves the method.

14 What is Attribute? Attribute is a class used to give additional declarative information for the class, method, property, indexer, etc. By using attributes you can identify the behavior of the class, method, property, indexer, etc. Syntax: [ Attribute_Name(argument(s))] The following are the different types of attributes in C#: Obsolete Conditional WebMethod DllImport

15 Obsolete: It is used to specify whether the class or method is deprecated or not. Obsolete attribute contains the following two arguments: i) Message ii) True/False If value is false, when deprecated method is used in the program then the program will execute with. If value is True, when deprecated method is used in application then compilation error will be displayed.

16 Obsolete:

17 User defined Attributes
User defined attribute can be used to give information about the class or method i.e whether the class is user defined class or abstract class, base class, etc. For method you can specify whether it is user defined method, abstract method, virtual method, etc. Attribute class in System namespace is a base class for custom attribute or user defined attribute.

18 User defined Attributes

19 Refrence


Download ppt "Indexer AKEEL AHMED."

Similar presentations


Ads by Google