In C#, reflection is a process to get metadata of a type at runtime . The System.Reflection namespace contains required classes for reflection such as: Type MemberInfo ConstructorInfo MethodInfo FieldInfo PropertyInfo TypeInfo EventInfo Module Assembly AssemblyName Pointer etc. C# Type class C# Type class represents type declarations for class types, interface types, enumeration types, array types, value types etc. It is found in System namespace. It inherits System.Reflection.MemberInfo class. C# Type Properties A list of important properties of Type class are given below: Property Description Assembly Gets the Assembly for this type. AssemblyQualifiedName Gets the Assembly qualified name for this type. Attributes Gets the Attributes associated with the type. BaseType Gets the base or parent type. FullName Gets the fully qualified name of the type. IsAbstract is used to check if the type is Abstract. IsArray is used to check if the type is Array. IsClass is used to check if the t...
In C#, the "throw" keyword is used to throw an exception when an error occurs in your code. However, there are two variations of the "throw" statement: "throw" and "throw ex" . We will look at the distinctions between "throw" and "throw ex" in C# in this article. In C#, the "throw" keyword is used to declare an exception. When an exception is thrown, the code that can handle it uses a catch block to capture it. The "throw" keyword is typically used to throw a new exception object, which can be created using the "new" keyword. For example, look at the below code: C# Code: try { // Some code that could potentially throw an exception } catch (Exception ex) { // Handle the exception ...
Constructor is a special method of the class that is automatically invoked when an instance of the class is created is called a constructor. the main use of the constructor is to initialize private fields of the class when you have not created a constructor in the class the compiler will automatically create a default constructor of the class. - The default constructor initializes all numeric fields in the class to zero and all string and objects fields to null. - A class can have any no. of constructors. - A constructor doesn't have any return type not even void. - A static constructor can't be parametrized. - Within a class you can create only one static constructor. Types of constructors - 1. Default Constructor - A constructor without any parameters is called default constructor. - The drawback of the default constructor is that every instance of the class will be initialized to the same values, and it is not possible to initialize each instance of the class with different...
Comments
Post a Comment