Found 33676 Articles for Programming

Queries for counts of array elements with values in given range in C++

Ayush Gupta
Updated on 09-Oct-2020 09:21:35

663 Views

In this problem, we are given an array arr[] and Q queries, each can be one of the two types, {1, L, R}− For the count of array elements in the range [L, R].{2, index, val}− For updating the element at index with val.Our task is to create a program to solve the Queries for counts of array elements with values in given range in C++.Let’s take an example to understand the problem, Input:arr[] = {1, 5, 2, 4, 2, 2, 3, 1, 3}Q = 3Query = { {1, 4, 8}, {2, 6, 5}, {1, 1, 4}}Ouput:3 7ExplanationQuery 1: count ... Read More

Queries for counts of multiples in an array in C++

Ayush Gupta
Updated on 09-Oct-2020 09:30:02

377 Views

In this problem, we are given an arr[] and Q queries each consisting of a value m. Our task is to create a program to solve the Queries for counts of multiples in an array in C++.Problem DescriptionFor solving the queries, we need to count all the numbers that are multiples of m. For this we will check for elements divisible by m.Let’s take an example to understand the problem, Input:arr[] = {4, 7, 3, 8, 12, 15}Q = 3 query[] = {2, 3, 5}Ouput:3 3 1ExplanationQuery 1: m = 2, multiples in the array = 4, 8, 12. Count ... Read More

What is the implicit implementation of the interface and when to use implicit implementation of the interface in C#?

Nizamuddin Siddiqui
Updated on 05-Aug-2020 11:46:41

868 Views

C# interface members can be implemented explicitly or implicitly.Implicit implementations don't include the name of the interface being implemented before the member name, so the compiler infers this. The members will be exposed as public and will be accessible when the object is cast as the concrete type.The call of the method is also not different. Just create an object of the class and invoke it.Implicit interface cannot be used if there is same method name declared in multiple interfacesExampleinterface ICar {    void displayCar(); } interface IBike {    void displayBike(); } class ShowRoom : ICar, IBike {   ... Read More

How to use order by, group by in c#?

Nizamuddin Siddiqui
Updated on 05-Aug-2020 09:07:34

3K+ Views

Order by is used to sort the arrays in the ascending or in the descending orderGroupBy operator belong to Grouping Operators category. This operator takes a flat sequence of items, organize that sequence into groups (IGrouping) based on a specific key and return groups of sequenceExampleclass ElectronicGoods {    public int Id { get; set; }    public string Name { get; set; }    public string Category { get; set; }    public static List GetElectronicItems() {       return new List() {          new ElectronicGoods { Id = 1, Name = "Mobile", Category = ... Read More

How to subscribe to an Event in C# and can we have multiple subscribers to one Event in a C#?

Nizamuddin Siddiqui
Updated on 05-Aug-2020 08:54:19

3K+ Views

Events enable a class or object to notify other classes or objects when something of interest occurs.The class that raises the event is called the publisher and the classes that handle the event are called subscribers.In the EventAn event can have multiple subscribers. A subscriber can handle multiple events from multiple publishers.Events that have no subscribers are never raised.The publisher determines when an event is raised; the subscribers determine what action is taken in response to the event.Exampleclass Program {    static void Main() {       var video = new MP4() { Title = "Eminem" };     ... Read More

What is #if DEBUG and How to use it in C#?

Nizamuddin Siddiqui
Updated on 05-Aug-2020 08:49:08

10K+ Views

In Visual Studio Debug mode and Release mode are different configurations for building your .Net project.Select the Debug mode for debugging step by step their .Net project and select the Release mode for the final build of Assembly file (.dll or .exe).The Debug mode does not optimize the binary it produces because the relationship between source code and generated instructions is more complex.This allows breakpoints to be set accurately and allows a programmer to step through the code one line at a time.The Debug configuration of your program is compiled with full symbolic debug information which help the debugger figure ... Read More

What is bin and obj folder in C#?

Nizamuddin Siddiqui
Updated on 05-Aug-2020 08:46:35

1K+ Views

Whenever we write a C# code and build or run the solution it generates 2 folders −binobjThese bins and obj has the compiled codeWhy do we have 2 folders?The reason is the compilation process goes through 2 stepscompilinglinkingIn the compiling every individual file is compiled into individual unitsThese compiled files will be later linked into one unit which can be a dll or an exeWhatever happens in the compiled phase will be added into obj folderThe final compilation that is the linked phase will go into bin folderThis obj folder is used in Conditional compilation or incremental compilationEx − I ... Read More

What is the difference between IEnumerable and IQueryable in C#?

Nizamuddin Siddiqui
Updated on 05-Aug-2020 08:43:49

10K+ Views

IEnumerable exists in System.Collections Namespace.IQueryable exists in System. Linq Namespace.Both IEnumerable and IQueryable are forward collection.IEnumerable doesn’t support lazy loadingIQueryable support lazy loadingQuerying data from a database, IEnumerable execute a select query on the server side, load data in-memory on a client-side and then filter data.Querying data from a database, IQueryable execute the select query on the server side with all filters.IEnumerable Extension methods take functional objects.IQueryable Extension methods take expression objects means expression tree.ExampleIEnumerabledbContext dc = new dbContext (); IEnumerable list = dc.SocialMedias.Where(p => p.Name.StartsWith("T")); list = list.Take(1); Sql statement generated for the above querySELECT [t0].[ID], [t0].[Name] FROM ... Read More

What is Binary Serialization and Deserialization in C# and how to achieve Binary Serialization in C#?

Nizamuddin Siddiqui
Updated on 05-Aug-2020 08:35:45

3K+ Views

Converting an Object to a Binary format which is not in a human readable format is called Binary Serialization.Converting back the binary format to human readable format is called deserialization?To achieve binary serialization in C# we have to make use of library System.Runtime.Serialization.Formatters.Binary AssemblyCreate an object of BinaryFormatter class and make use of serialize method inside the classExampleSerialize an Object to Binary [Serializable] public class Demo {    public string ApplicationName { get; set; } = "Binary Serialize";    public int ApplicationId { get; set; } = 1001; } class Program {    static void Main()    {     ... Read More

Sum of first N natural numbers which are divisible by 2 and 7 in C++

sudhir sharma
Updated on 05-Aug-2020 08:20:00

169 Views

In this problem, we are given a number N. Our task is to find the sum of first N natural numbers which are divisible by 2 and 7.So, here we will be given a number N, the program will find the sum of numbers between 1 to N that is divisible by 2 and 7.Let’s take an example to understand the problem, Input −N = 10Output −37Explanation −sum = 2 + 4 + 6 + 7 + 8 + 10 = 37So, the basic idea to solve the problem is to find all the numbers that are divisible by 2 ... Read More

Advertisements