Karthikeya Boyini has Published 2193 Articles

Return the total elements in a sequence as a 64-bit signed integer in C#

karthikeya Boyini

karthikeya Boyini

Updated on 23-Jun-2020 07:08:30

96 Views

Firstly, set a string array.string[] num = { "One", "Two", "Three", "Four", "Five"};Use the Linq LongCount method to get the count of elements.num.AsQueryable().LongCount();Here is the complete code −Example Live Demousing System; using System.Collections.Generic; using System.Linq; class Demo {    static void Main() {       string[] num = { "One", ... Read More

Object Initializer in C#

karthikeya Boyini

karthikeya Boyini

Updated on 23-Jun-2020 07:06:25

178 Views

Initialize an object of a class with object initialize.Using it, you can assign values to the fields at the time of creating an object.We created Employee object and assigned values using curly bracket at the same time.Employee empDetails = new Employee() {    EID = 10,    EmpName = "Tim", ... Read More

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

380 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

903 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

381 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

466 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

9K+ 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

9K+ 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

Advertisements