Arjun Thakur has Published 1109 Articles

c# Put spaces between words starting with capital letters

Arjun Thakur

Arjun Thakur

Updated on 21-Jun-2020 15:52:44

3K+ Views

To place spaces in between words starting with capital letters, try the following example −Firstly, set the string.var str = "WelcomeToMyWebsite";As you can see above, our string isn’t having spaces before capital letter. To add it, use LINQ as we have done below −str = string.Concat(str.Select(x => Char.IsUpper(x) ? " ... Read More

What is the difference between a list and an array in C#?

Arjun Thakur

Arjun Thakur

Updated on 21-Jun-2020 15:44:15

7K+ Views

An array stores a fixed-size sequential collection of elements of the same type, whereas list is a generic collection.To define a List −List

C# Numeric Promotion

Arjun Thakur

Arjun Thakur

Updated on 21-Jun-2020 15:33:17

251 Views

Numeric promotion as the name suggests is the promotion of smaller types to larger types like short to int.In the below example, we have seen numeric promotion in Arithmetic Operator multiply.The short types are automatically promoted to larger types −Exampleusing System; class Program {    static void Main() { ... Read More

How to compare two tuples in C#?

Arjun Thakur

Arjun Thakur

Updated on 21-Jun-2020 15:26:02

316 Views

Tuple comparison came after C# 7.3.Easily compare two tuples using the equality operator in C#.Let’s say we have two tuples −var one = (x: 1, y: 2); var two = (p: 1, 2: 3, r: 3, s:4);To compare them, just use the == operator −if (one == two) Console.WriteLine("Both the ... Read More

What are the differences between a static and a non-static class in C#?

Arjun Thakur

Arjun Thakur

Updated on 21-Jun-2020 15:13:24

1K+ Views

The following is the difference between a static and non-static class −Non-static classes can be instantiated, whereas static classes cannot be instantiated i.e. you cannot use the new keyword to create a variable of the class typeStatic classes can only have static methods.Non-static classes can have instance method and static methods.ou access ... Read More

What is difference between internal and private modifiers in C#?

Arjun Thakur

Arjun Thakur

Updated on 21-Jun-2020 15:02:21

1K+ Views

Internal Access SpecifierInternal access specifier allows a class to expose its member variables and member functions to other functions and objects in the current assembly.Any member with internal access specifier can be accessed from any class or method defined within the application in which the member is defined.The following is ... Read More

How to add items to a list in C#?

Arjun Thakur

Arjun Thakur

Updated on 21-Jun-2020 14:58:17

675 Views

Firstly, declare a list −var teams = new List();To add items to a C# list, use the Add() method −teams.Add("US"); teams.Add("Canada"); teams.Add("India"); teams.Add("Australia");You can try to run the following code to add items to a list in C# −Exampleusing System; using System.Collections.Generic; public class Demo {    public static ... Read More

Variable Arguments (Varargs) in C#

Arjun Thakur

Arjun Thakur

Updated on 21-Jun-2020 13:59:58

4K+ Views

Use the param keyword to get the variable arguments in C#.Let us see an example to multiply integers. We have used params keyword to accept any number of int values −static int Multiply(params int[] b)The above allows us to find multiplication of numbers with one as well as two int ... Read More

How to convert a Decimal to Octal using C#?

Arjun Thakur

Arjun Thakur

Updated on 21-Jun-2020 13:43:30

299 Views

To get the octal equivalent, use a while loop for the decimal value and store the remainder in the array set for octal. Here we have set the remainder by mod 8 in the array.Then divide the number by 8 −while (dec != 0) {    oct[i] = dec % ... Read More

How command line arguments are passed in main method in C#?

Arjun Thakur

Arjun Thakur

Updated on 21-Jun-2020 13:31:42

269 Views

The Main() method is the entry point −static void Main(string[] args)The arguments array args is used to set arguments −string[] args)It will set the following if you add two arguments −var args = new string[] {"arg1", "arg2”}Here is the demo code −Exampleusing System; namespace Demo {    class HelloWorld ... Read More

Advertisements