Karthikeya Boyini has Published 2383 Articles

Multiple Where clause in C# Linq

karthikeya Boyini

karthikeya Boyini

Updated on 23-Jun-2020 07:02:56

4K+ Views

Filter collections using Where clause in C#. A single query expression may have multiple where clauses.Firstly, set a collection −IList employee = new List() {    new Employee() { EmpID = 1, EmpName = "Tom", EmpMarks = 90, Rank = 8} ,    new Employee() { EmpID = 2, EmpName ... Read More

Return a C# tuple from a method

karthikeya Boyini

karthikeya Boyini

Updated on 23-Jun-2020 06:52:32

330 Views

Firstly, create a tuple as shown below that calls a method.var tuple = Show();The above statement calls the following method −static Tuple Show()Under the method, return the tuple as shown below −Example Live Demousing System; public class Demo {    public static void Main() {       var tuple = ... Read More

C# Round-trip ("R") Format Specifier

karthikeya Boyini

karthikeya Boyini

Updated on 22-Jun-2020 15:39:31

636 Views

This round-trip ("R") format specifier is supported for the Single, Double, and BigInteger types.It ensures that a numeric value converted to a string is parsed back into the same numeric value.Let us see an example −Firstly, we have a double variable.double doubleVal = 0.91234582637;Now, use the ToString() method: and set ... Read More

FileNotFoundException in C#

karthikeya Boyini

karthikeya Boyini

Updated on 22-Jun-2020 15:31:49

223 Views

If a File you are trying to find does not exist, then FileNotFoundException occurs.Here, we are try to find a file that does not exist using StreamReader() method.reader = new StreamReader("new.txt"))To read it we have used the following method −reader.ReadToEnd();Let us see the complete code.Exampleusing System.IO; using System; class Program ... Read More

How to remove items from a list in C#?

karthikeya Boyini

karthikeya Boyini

Updated on 22-Jun-2020 15:30:13

367 Views

Firstly, set a list and add elements.List myList = new List(); myList.Add("Jennings"); myList.Add("James"); myList.Add("Chris");Let’s say you need to delete the element “James” now. For that, use the Remove() method.myList.Remove("James");Here is the complete code.Example Live Demousing System.Collections.Generic; using System; class Program {    static void Main() {       List myList ... Read More

How to print the contents of array horizontally using C#?

karthikeya Boyini

karthikeya Boyini

Updated on 22-Jun-2020 15:29:28

2K+ Views

Set an array.int[] array = new int[] { 50, 100, 150, 200, 250, 300, 350, 400 };Now, if you will print this array using a loop and new line, then the arrays will be visible vertically.To work it horizontally, use the Join() method and set spaces to separate array elements.string.Join(" ... Read More

C# Program to remove whitespaces in a string

karthikeya Boyini

karthikeya Boyini

Updated on 22-Jun-2020 15:28:33

7K+ Views

Let’s say the following is the string −StringBuilder str = new StringBuilder("Patience is key!");To remove whitespace, you can use the replace method.str.Replace(" ", "");Let us see the complete code.Example Live Demousing System; using System.Text; class Demo {    static void Main() {       // Initial String       ... Read More

Represent Int32 as a Binary String in C#

karthikeya Boyini

karthikeya Boyini

Updated on 22-Jun-2020 15:27:53

6K+ Views

To represent Int632as a Binary string in C#, use the ToString() method and set the base as the ToString() method’s second parameter i.e. 2 for Binary.Int32 represents a 32-bit signed integer.Firstly, set an Int64 variable −int val = 30;Now, convert it to a binary string by including 2 as the ... Read More

How to iterate two Lists or Arrays with one foreach statement in C#?

karthikeya Boyini

karthikeya Boyini

Updated on 22-Jun-2020 15:18:04

5K+ Views

Set two arrays.var val = new [] { 20, 40, 60}; var str = new [] { "ele1", "ele2", "ele3"};Use the zip() method to process the two arrays in parallel.var res = val.Zip(str, (n, w) => new { Number = n, Word = w });The above fetches both the arrays ... Read More

C# Program to remove duplicate characters from String

karthikeya Boyini

karthikeya Boyini

Updated on 22-Jun-2020 15:16:43

9K+ Views

Use Hashset to remove duplicate characters.Here is the string −string myStr = "kkllmmnnoo";Now, use HashSet to map the string to char. This will remove the duplicate characters from a string.var unique = new HashSet(myStr);Let us see the complete example −Example Live Demousing System; using System.Linq; using System.Collections.Generic; namespace Demo { ... Read More

Advertisements