Download a File from a URL in C#

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

9K+ Views

A file can be downloaded from a URL using web client. It is available in System.Net namespace.The WebClient class provides common methods for sending data to or receiving data from any local, intranet, or Internet resource identified by a URI.The web client can be said as an application or web browser (like Google Chrome, Internet Explorer, Opera, Firefox, Safari) which is installed in a computer and used to interact with Web servers upon user’s request. It is basically a consumer application which collects processed data from servers.A Client and a Server are two parts of a connection, these are two ... Read More

Populate XDocument from String in C#

Nizamuddin Siddiqui
Updated on 19-Aug-2020 11:35:17

2K+ Views

XML is a self-describing language and it gives the data as well as the rules to identify what information it contains. Like HTML, XML is a subset of SGML - Standard Generalized Markup Language.The XDocument class contains the information necessary for a valid XML document. This includes an XML declaration, processing instructions, and comments.Note that we only have to create XDocument objects if we require the specific functionality provided by the XDocument class. In many circumstances, we can work directly with XElement. Working directly with XElement is a simpler programming model.XDocument derives from XContainer. Therefore, it can contain child nodes. ... Read More

Get the Name of the Current Executable in C#

Nizamuddin Siddiqui
Updated on 19-Aug-2020 11:31:26

5K+ Views

There are several ways to get the name of the current executable in C#.Using System.AppDomain −Application domain provides isolation between code running in different app domains. App Domain is a logical container for code and data just like process and has separate memory space and access to resources. App domain also serves as a boundary like process does to avoid any accidental or illegal attempts to access the data of an object in one running application from another.System.AppDomain class provides us the ways to deal with application domain. It provides methods to create new application domain, unload domain from memory ... Read More

Find Character in First String Present at Minimum Index in Second String in Python

Arnab Chakraborty
Updated on 19-Aug-2020 11:31:23

362 Views

Suppose we have a string str and another string patt, we have to find determine the character in patt that is present at the minimum index of str. If no character patt1 is present in str1 then return -1.So, if the input is like str = "helloworld" and patt = "wor", then the output will be 'o' as 'o' is present at minimum index in strTo solve this, we will follow these steps −for i in range 0 to size of patt, dofor j in range 0 to size of Str, doif patt[i] is same as Str[j] and j < ... Read More

Find Sum of All Elements in a Matrix Except Given Cell's Row and Column in Python

Arnab Chakraborty
Updated on 19-Aug-2020 11:30:03

923 Views

Suppose we have a 2D matrix and a set of cell indexes. Cell indices are represented as (i, j) where i is row and j is column, now, for every given cell index (i, j), we have to find the sums of all matrix elements excluding the elements present in ith row and/or jth column.So, if the input is like223457643cell indices = [(0, 0), (1, 1), (0, 1)], then the output will be [19, 14, 20]To solve this, we will follow these steps −n := size of ind_arrans := a new listfor i in range 0 to n, doSum := ... Read More

Find Substrings that Contain All Vowels in Python

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

885 Views

Suppose we have a string in lowercase alphabets, we have to find substrings that contain all the vowels at least once and there exist no consonants in that substrings.So, if the input is like "helloworldaeiouaieuonicestring", then the output will be ['aeiou', 'aeioua', 'aeiouai', 'aeiouaiu', 'eioua', 'eiouai', 'eiouaiu']To solve this, we will follow these steps −n := size of sfor i in range 0 to n, domy_map := a new mapfor j in range i to n, doif s[j] not vowel, thencome out from the loopmy_map[s[j]] := 1if size of my_map is same as 5, thendisplay s[from index i to j ... Read More

Get Path to 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 Subsequences with Maximum Bitwise AND and Bitwise OR in Python

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

764 Views

Suppose we have an array of n elements, we have to show the maximum sum by choosing two subsequences of the array (they may or may not be different) so that the sum of bit-wise AND operation of all elements of the first subsequence and bit-wise OR operation of all the elements of the second subsequence is maximum.So, if the input is like A = {4, 6, 7, 2}, then the output will be 14 as we are getting maximum AND value by selecting 7 only and maximum OR value by selecting all (4 | 6 | 7 | 2) ... Read More

Best Data Type 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 Sub-Arrays with 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

Advertisements