Characteristics of Unsafe Code are:
The keyword dynamic was first introduced in.NET 4.0. There are two types of computer programming languages: highly typed and dynamically typed. All type checks occur at compile time in strongly typed, but all types of checks happen at run time in dynamic types.
When working with Microsoft Office, the dynamic keyword is very useful. During runtime, both reflection and dynamic are used to work on an object. However, there are some distinctions:
An anonymous function that can be used to build delegates or expression tree types is a lambda expression. You can build local functions that can be supplied as arguments or returned as the value of function calls using lambda expressions. Lambda expressions come in handy for writing LINQ query expressions in particular.
C# is an object-oriented programming language that supports four different Object-oriented Programming principles.
This is a term that refers to the process of tying together code and data and keeping it safe from alteration by other programs and classes. It’s a container that blocks code and data from being accessed by a program specified outside of it.
To promote efficiency and security within the program, this object-oriented notion protects anything other than the relevant data about any produced object.
When one object uses the properties of another, this is known as inheritance.
It is a feature that allows one interface to serve as the base class for additional interfaces. The phrase “one interface, multiple actions” is frequently used to describe this concept.
The differences are as follows:
Break | Continue |
Both switch and loop (for, while, and do-while ) statements can employ break statements. Just the loop (for, while, do) statements can employ continue statements. | Just the loop (for, while, do) statements can employ continue statements. |
The switch or loop statements are terminated when the break statement is executed, and the program ends suddenly. | A continue statement cannot be used to end a loop; it just continues the loop to the next iteration level without completing the immediate next step. |
When the compiler sees a break statement and exits the inner loop, the loop or switch quits instantly. | The next loop iteration is triggered by a continuation placed inside a nested loop within a switch. |
The utilizing statement is used to manage the use of one or more resources within the program. Resources are consumed and released in a continual cycle. This statement’s primary purpose is to automatically manage and release unused resources. When you’re done creating the object that’s utilizing the resource, make sure to contact the object’s dispose function to release the resources it’s utilizing; this is where using statements come in handy.
For example:
using (MyResource abc = new MyResource()) { abc.program(); } Gets translated to, MyResource abc= new MyResource(); try { myRes.program(); } finally { / / Check for a null resource; if (abc! = null) / / Call the object’s Dispose method. ((IDisposable)abc).Dispose(); }
Using System; public class Program { public static void Main(string[] args) { int val = (byte)+(char)-(int)+(long)-2 ; Console.WriteLine(val) ; } }
Answer: Option: c)
A computer program’s structure and behavior can be monitored and modified using reflection. It’s a way to look at the structure of assemblies while they’re running (classes, resources, methods). At run-time, reflection is the ability to obtain relevant data, metadata, and program details (assemblies). To conduct reflections in C#, we must include the System.Reflection namespace.
Take a look at the C# programs below, which will yield some meta information.
public class MyClass { public virtual int Add(int numb1, int numb2) { return numb1 + numb2; } public virtual int Subtract(int numb1, int numb2) { return numb1 – numb2; } } static void Main(string[] args) { MyClass oMyClass = new MyClass(); //Type information. Type oMyType = oMyClass.GetType(); //Method information. MethodInfo oMyMethodInfo = oMyType.GetMethod(“Subtract”); Console.WriteLine(“nType information:” + oMyType.FullName); Console.WriteLine(“nMethod info:” + oMyMethodInfo.Name); Console.Read(); }
A raised problem that may occur during the execution of the program is referred to as an exception. When an exception is raised, handling exceptions provides a straightforward mechanism to send control back to the program. Exceptions in C# are handled using four keywords: try, catch, finally, and throw.
A raised exception identifies a specific section of code that has to be treated. There is no limit to how many catch blocks you can employ in your application to deal with various types of exceptions.
Within this catch block, you can handle the raised exception. You can specify the measures you wish to take to resolve the mistake, or you can simply ignore it by having the code suppress it.
Regardless of the error, if you’d like a sequence of instructions to be presented, you may utilize those statements within the final block, and it will do so.
The throw statement can be used to throw an exception. It will show you what kind of mistake you’re making.
Syntax:
try { / / exception handling starts with try block } catch( ExceptionName ea1 ) { / / errors are handled within the catch block } catch( ExceptionName e2 ) { / / more catch block } catch( ExceptionName eN ) { / / more catch block to handle multiple exception raised } finally { / / last block of the exception handling }
Answer- A destructor is a member that performs the exact opposite of a constructor. Destructors, unlike constructors, primarily erase the object. Just like the constructor, the name of the destructor must match exactly with the class name. A destructor block always starts with the tilde (~) symbol.
Syntax:
~class_name() { / /code }
A destructor is automatically utilized:
If we wish to send an object over the network, we must first turn it into a stream of bytes. Serialization is the conversion of a complicated object into a stream of bytes for storage (in a database, file, cache, etc.) or transport. Its primary function is to save an object’s state.
The process of converting an object from a stream of bytes to its original form is known as de-serialization.
Different types of Serializations are:
All public, private, and read-only members are serialized and converted into a stream of bytes throughout this procedure. This is utilized when we wish to convert all of our items at once.
Only public members are transformed to SOAP format in this process. This is a term that is used in the context of online services.
Only public members are transformed to XML in this procedure. This is a one-of-a-kind serialization. System.Xml and System.Xml.Serialization is required namespaces.
using System; public class Program { public static void Main(string[] args) int[] arr = new int[2]; arr[1] = 10; Object o = arr; int[] arr1 = (int[])o; arr1[1] = 100; Console.WriteLine(arr[1]); ((int[])o)[1] = 1000; Console.WriteLine(arr[1]); } }
a) 10
10
b) 10
100
c) 10
1000
d) 100
1000
Answer. OPTION: d)