Programming Articles - Page 1782 of 3366

How to get a path to the desktop for current user in C#?

Nizamuddin Siddiqui
Updated on 19-Aug-2020 11:27:58

5K+ Views

The desktop path of the current user can be fetched by using Environment.SpecialFolder. The Environment.SpecialFolder gets the path to the system special folder that is identified by the specified enumeration.string desktopPath =Environment.GetFolderPath(Environment.SpecialFolder.Desktop)The System.Environment Class provides information about the current environment and platform. The System.Environment Class uses to retrieve Environment variable settings, Version of the common language runtime, contents of the call stack etc. This class cannot be inherited.Environment class is static class which Provides the system configuration, Current program execution Environment as wel some properties for string manipulation such as news line, System Namespace represents the Environment Class.Environment class is ... Read More

Find sub-arrays from given two arrays such that they have equal sum in Python

Arnab Chakraborty
Updated on 19-Aug-2020 11:24:34

379 Views

Suppose we have two arrays P and Q whose size are N, they are holding numbers 1 to N. We have to find sub-arrays from the given arrays so that they have equal sum. Finally return the indices of such sub-arrays. If there is no solution, then return -1.So, if the input is like P = [2, 3, 4, 5, 6], Q = [9, 3, 2, 6, 5], then the output will be Indices in first array : 0, 1, 2 and indices in second array: 0, so P[0..2] = 2 + 3 + 4 = 9 and Q[0] = ... Read More

Find smallest range containing elements from k lists in C++

Arnab Chakraborty
Updated on 19-Aug-2020 11:22:18

96 Views

Suppose we have k different lists. The elements are sorted. We have to search the smallest range that includes at least one number from each of the k different lists. Here the range [a, b] is smaller than range [c, d] when b-a < d-c or a < c if b-a == d-c.So if the input is like [[4, 10, 15, 25, 26], [0, 9, 14, 20], [5, 18, 24, 30]], then the output will be [14, 18]To solve this, we will follow these steps −minRange := inf, maxRange := -inf, rangeSize := inf, tempMinRange := inf, tempMaxRange := -infn ... Read More

Find Shortest distance from a guard in a Bankin Python

Arnab Chakraborty
Updated on 19-Aug-2020 11:19:35

201 Views

Suppose we have a matrix that is filled with three letters 'O', 'G', and 'W' where 'O' is representing open space, 'G' is representing guards and 'W' is representing walls in a bank, we have to replace all of the O's in the matrix with respect of their shortest distance from one guard, we cannot go through any walls. In the output matrix guards are replaced with 0 and walls are replaced by -1.So, if the input is likeOOOOGOOOWOOWOOOGWWWOOOOOGthen the output will be33210233-111-14320-1-1-1112210To solve this, we will follow these steps −M := 5N := 5dir_row := [-1, 0, 1, 0]dir_col ... Read More

What is the best data type to use for currency in C#?

Nizamuddin Siddiqui
Updated on 19-Aug-2020 11:24:37

7K+ Views

The best datatype to use for currency in C# is decimal. The decimal type is a 128-bit data type suitable for financial and monetary calculations. The decimal type can represent values ranging from 1.0 * 10^-28 to approximately 7.9 * 10^28 with 28-29 significant digits. To initialize a decimal variable, use the suffix m or M.decimal b = 2.1m;The below example shows the min and max value of decimal.Example Live Demousing System; namespace DemoApplication{    public class Program{       public static void Main(){          Console.WriteLine($"Deciaml Min Value: {decimal.MinValue}");          Console.WriteLine($"Deciaml Max Value: {decimal.MaxValue}"); ... Read More

Find same contacts in a list of contacts in Python

Arnab Chakraborty
Updated on 19-Aug-2020 11:16:45

278 Views

Suppose we have a list of contacts holding username, email and phone number in any order, we have to find the same contacts (When same person have many different contacts) and return the same contacts together. We have to keep in mind that −A contact can store username, email and phone fields according to any order.Two contacts are same if they have either same username or same email or same phone number.So, if the input is like Contacts = [{"Amal", "amal@gmail.com", "+915264"}, { "Bimal", "bimal321@yahoo.com", "+1234567"}, { "Amal123", "+1234567", "amal_new@gmail.com"}, { "AmalAnother", "+962547", "amal_new@gmail.com"}], then the output will be [0, ... Read More

How to get only Date portion from DateTime object in C#?

Nizamuddin Siddiqui
Updated on 02-Sep-2023 13:12:30

65K+ Views

There are several ways to get only date portion from a DateTime object.ToShortDateString() − Converts the value of the current DateTime object to its equivalent short date string representation.Returns a string that contains the short date string representation of the current DateTime object.ToLongDateString() − Converts the value of the current DateTime object to its equivalent long date string representation.Returns a string that contains the long date string representation of the current DateTime object.ToString() − One more way to get the date from DateTime is using ToString() extension method.The advantage of using ToString() extension method is that we can specify the ... Read More

Find multiplication of sums of data of leaves at same levels in Python

Arnab Chakraborty
Updated on 19-Aug-2020 11:12:34

140 Views

Suppose we have a Binary Tree. We have to perform following operations −For each level, find sum of all leaves if there are leaves at this level. Otherwise ignore it.Find multiplication of all sums and return it.So, if the input is likethen the output will be 270. First two levels have no leaves. Third level has single leaf 9. Last level has four leaves 2, 12, 5 and 11. So result is 9 * (2 + 12 + 5 + 11) = 270To solve this, we will follow these steps −if root is null, thenreturn 0res := 1que := a ... Read More

How to convert an integer to hexadecimal and vice versa in C#?

Nizamuddin Siddiqui
Updated on 19-Aug-2020 11:13:29

12K+ Views

Converting Integer to HexadecimalAn integer can be converted to a hexadecimal by using the string.ToString() extension method.Integer Value: 500 Hexadecimal Value: 1F4Converting Hexadecimal to Integer −A hexadecimal value can be converted to an integer using int.Parse or convert.ToInt32int.Parse − Converts the string representation of a number to its 32-bit signed integer equivalent. A return value indicates whether the operation succeeded.Hexadecimal Value: 1F4 Integer Value: 500Convert.ToInt32 −Converts a specified value to a 32-bit signed integer.Hexadecimal Value: 1F4 Integer Value: 500Converting Integer to Hexadecimal −string hexValue = integerValue.ToString("X");Example Live Demousing System; namespace DemoApplication{    public class Program{       public static void ... Read More

How to validate an email address in C#?

Nizamuddin Siddiqui
Updated on 19-Aug-2020 11:08:58

6K+ Views

There are several ways to validate an email address in C#.System.Net.Mail −The System.Net.Mail namespace contains classes used to send electronic mail to a Simple Mail Transfer Protocol (SMTP) server for delivery.System.Text.RegularExpressions − Represents an immutable regular expression.Use the below expression@"^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1, 3}\.[0-9]{1, 3}\.[0-9]{1, 3}\.)|(([a-zA-Z0-9\-]+\.)+))([azA-Z]{2, 4}|[0-9]{1, 3})(\]?)$"We can use the MailAddress class of the System.Net.Mail namespace to validate an email addressExample Live Demousing System; using System.Net.Mail; namespace DemoApplication{    class Program{       public static void Main(){          try{             string email = "hello@xyzcom";             Console.WriteLine($"The email is {email}"); ... Read More

Advertisements