Found 26504 Articles for Server Side Programming

Explain how reflection works in .NET framework

Akshay Khot
Updated on 19-May-2021 08:10:23

390 Views

A C# program compiles to a DLL assembly that contains the compiled C# code along with the metadata for the runtime, and other resources. C# provides a reflection API that lets us inspect the metadata and compiled code at runtime.Using reflection, it's possible to −Access the assembly metadata for all types inside the assemblyObtain a list of types and their members (methods, properties, etc.)Dynamically invoke the type members at runtime.Instantiate objects by only providing their nameBuild assembliesIn a traditional program, when you compile the source code to the machine code, the compiler removes all the metadata about the code. However, ... Read More

What are some of the important namespaces in C#? Provide a brief description of each

Akshay Khot
Updated on 19-May-2021 08:07:39

628 Views

.NET contains a lot of namespaces and many more, if you include the third-party libraries. However, there are a few that you will use over and over. Here are the twenty that will get you through 80% of the common, recurring programming problems.SystemContains the most fundamental types. These include commonly used classes, structures, enums, events, interfaces, etc.System.TextContains classes that represent ASCII and Unicode character encodings. Classes for converting blocks of characters to and from blocks of bytes.System.Text.RegularExpressionsProvides regular expression functionality.System.LinqProvides classes and interfaces that support queries that use Language-Integrated Query (LINQ).System.XML.LinqContains the classes for LINQ to XML. LINQ to XML ... Read More

How does the event pattern work in .NET?

Akshay Khot
Updated on 19-May-2021 08:05:42

557 Views

Events are a simplified pattern that uses delegates. In C#, all delegates have the multicast capability, i.e., an instance of a delegate can represent not just a single method but a list of methods. For example −Exampledelegate int Transformer(int x); static void Main(){    Transformer perform = x =>{       int result = x * x;       Console.WriteLine(result);       return result;    };    perform += x =>{       int result = x * x * x;       Console.WriteLine(result);       return result;    };    perform(2); // prints ... Read More

Explain the difference between const and readonly keywords in C#

Akshay Khot
Updated on 19-May-2021 07:50:10

780 Views

In C#, both the const and readonly keywords are used to define immutable values which cannot be modified once they are declared. However, there are some important differences between the two.constThe const modifier declares the constant values that are known at compile-time and do not change, i.e. they are immutable. In C#, you can mark only the built-in types as const. User-defined types such as classes, structs, etc. cannot be const. Also, class member types such as methods, properties, or events cannot be marked as constants.You must initialize the constants during declaration.class Period{    public const int hours = 12; ... Read More

What operators C# provides to deal with null values?

Akshay Khot
Updated on 19-May-2021 07:49:08

401 Views

C# has the following three operators to deal with the null values −null-coalescing operator (??)Allows you to get the value of a variable if it's not null, alternatively specifying a default value that can be used.It replaces the following expression in C# −string resultOne = value != null ? value : "default_value";with the following expression −string resultTwo = value ?? "default_value";Here is an example that illustrates this.Exampleusing System; class Program{    static void Main(){       string input = null;       string choice = input ?? "default_choice";       Console.WriteLine(choice); // default_choice       string ... Read More

How do interfaces work in C#?

Akshay Khot
Updated on 19-May-2021 07:47:44

561 Views

An interface defines a contract that will be implemented by a class or a struct. It can contain methods, properties, events, and indexers. An interface is similar to a class except that it doesn't hold any data and only specifies the behavior it can do (or more accurately, the class that implements it can do).A class can implement one or more interfaces. To implement an interface member, the class should have a public member with the same method definition as the interface member, i.e. same name and signature.For example, IComparer is an interface defined in the System.Collections namespace that defines ... Read More

What is the usage of ref, out, and in keywords in C#?

Akshay Khot
Updated on 19-May-2021 07:41:00

550 Views

In C#, most of the methods can have zero or more parameters which define the data that must be provided to the method. Any code that calls the method has to pass the data (called arguments) to the method. A method declares its inputs as parameters, and they're provided by calling code in the form of arguments.For example, consider the following method and subsequent method call.static void Greet(string greeting){    Console.WriteLine(greeting); } ... Greet("Hello");In the above example, greeting is a parameter of the Greet() method, and "Hello" is an argument passed to the method.When you call a method and pass ... Read More

Provide a brief overview of the C# and .NET ecosystem

Akshay Khot
Updated on 19-May-2021 07:40:00

676 Views

C# is an object-oriented, type-safe and general-purpose programming language, which focuses on making the programmers productive. It tries to achieve this productivity through expressiveness, simplicity and a focus on performance. It works on different platforms such as Windows, Mac, and Linux.Type-SafetyC# is a statically typed language. That means the types are verified when you compile a program. This eliminates a large set of errors before the program even runs.Garbage CollectionAutomatic memory management is an essential feature of C#. It has a garbage collector that runs along with the programs, reclaiming the unused memory. This frees the burden from programmers to ... Read More

Explain and contrast value types and reference types in C#

Akshay Khot
Updated on 19-May-2021 07:33:11

328 Views

In general, all types in C# can be divided into two main categories − value types and reference types. Let's look at each type in detail.Value TypesVariables of value types directly contain their data. Each variable has its own copy of the data. Hence it is impossible for a variable of value type to modify another object.A value type can be one of the following types −all numeric types, e.g., int, float, and doublechar and the bool typesstruct type orenumeration type.A value type simple contains the value. For example, the integer type contains the actual number, and not a pointer ... Read More

Program to find out the dot product of two sparse vectors in Python

Arnab Chakraborty
Updated on 18-May-2021 12:14:56

693 Views

Suppose, we have two sparse vectors represented in two lists. We have to return the dot product of the two sparse vectors. The vectors are represented as objects, and the lists are stored in a member variable 'nums' in the objects.So, if the input is like vector1 = [1, 0, 0, 0, 1], vector2 = [0, 0, 0, 1, 1], then the output will be 1 The dot product is 1 * 0 + 0 * 0 + 0 * 0 + 0 * 1 + 1 * 1 = 1.To solve this, we will follow these steps −res := ... Read More

Advertisements