Arjun Thakur has Published 1025 Articles

What are rvalue and lvalue in C#?

Arjun Thakur

Arjun Thakur

Updated on 21-Jun-2020 16:52:48

1K+ Views

The following are the types of expressions in C# −lvalue − An expression that is an lvalue may appear as either the left-hand or right-hand side of an assignment.rvalue − An expression that is an rvalue may appear on the right- but not left-hand side of an assignment.Variables are lvalues ... Read More

return keyword in C#

Arjun Thakur

Arjun Thakur

Updated on 21-Jun-2020 16:32:10

3K+ Views

The return statement is used to return value. When a program calls a function, the program control is transferred to the called function.The following is an example to learn about the usage of return statement in C#. Here, we are finding the average and returning the result using the return ... Read More

try keyword in C#

Arjun Thakur

Arjun Thakur

Updated on 21-Jun-2020 16:21:17

309 Views

A try block identifies a block of code for which particular exceptions is activated. It is followed by one or more catch blocks.try { }With that, you need to set catch statement as well to catch the exception −try {       // statements causing exception    } catch( ... Read More

Numbers in C#

Arjun Thakur

Arjun Thakur

Updated on 21-Jun-2020 16:08:01

283 Views

For numbers in C#, use the int type. It represents an integer, which is positive or negative whole number.Let us see how to add two integers in C# using mathematical operator + −using System; using System.Linq; class Program {    static void Main() {       int x ... Read More

Optimization Tips for C# Code

Arjun Thakur

Arjun Thakur

Updated on 21-Jun-2020 15:57:01

834 Views

The following are the tips −Prefer ListUse List whenever necessary. Working with ArrayList for the same work can make the working of code slower. This is specially if you are storing multiple types of objects within the same list.Use multiplication-shift operationPrefer multiplication-shift operation instead of division operator, since the usage ... Read More

c# Put spaces between words starting with capital letters

Arjun Thakur

Arjun Thakur

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

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

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

372 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

480 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

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

Advertisements