Arjun Thakur has Published 1109 Articles

What are integer literals in C#?

Arjun Thakur

Arjun Thakur

Updated on 20-Jun-2020 16:44:54

432 Views

An integer literal can be a decimal, or hexadecimal constant. A prefix specifies the base or radix: 0x or 0X for hexadecimal, and there is no prefix id for decimal. It can also have a suffix that is a combination of U and L, for unsigned and long, respectively.Here are ... Read More

Sort list of dictionaries by values in C#

Arjun Thakur

Arjun Thakur

Updated on 20-Jun-2020 16:42:53

985 Views

Firstly, let us create a dictionary −var d = new Dictionary(5);Now add the key and value −// add key and value d.Add("car", 25); d.Add("bus", 28); d.Add("motorbike", 17);Use orderby to order by values −var val = from ele in d orderby ele.Value ascending select ele;We have set ascending above to sort ... Read More

What are identifiers in C#?

Arjun Thakur

Arjun Thakur

Updated on 20-Jun-2020 16:37:21

773 Views

An identifier is a name used to identify a class, variable, function, or any other user-defined item. The basic rules for naming classes in C# are as follows −A name must begin with a letter that could be followed by a sequence of letters, digits (0 - 9) or underscore. ... Read More

Literals in C#

Arjun Thakur

Arjun Thakur

Updated on 20-Jun-2020 16:32:18

2K+ Views

The fixed values are called literals. The constants refer to fixed values that the program may not alter during its execution.Constants can be of any of the basic data types like an integer constant, a floating constant, a character constant, or a string literal. There are also enumeration constants as ... Read More

What does Array.SyncRoot property of array class do in C#?

Arjun Thakur

Arjun Thakur

Updated on 20-Jun-2020 16:31:20

255 Views

The Array.SyncRoot property is used to get an object that can be used to synchronize access to the Array. The classes that have arrays can also use the SyncRoot property to implement their own synchronization.Enumerating through a collection is not a thread safe procedure. The other threads may modify the collection ... Read More

What are string literals in C#?

Arjun Thakur

Arjun Thakur

Updated on 20-Jun-2020 16:28:38

298 Views

String literals or constants are enclosed in double quotes "" or with @"". A string contains characters that are similar to character literals: plain characters, escape sequences, and universal characters.Here are some examples of String Literals −“Hi, User" "You’re Welcome, \The following is an example showing the usage of string ... Read More

What does Array.IsSynchronized property of array class do in C#?

Arjun Thakur

Arjun Thakur

Updated on 20-Jun-2020 16:22:10

66 Views

The Array.IsSynchronized property in C gets a value indicating whether access to the Array is synchronized.The IsSynchronized property is implemented by Arrays because it is needed by the System.Collections.ICollection interface. Classes using arrays can also implement own synchronization using the SyncRoot property.The following is the syntax −public bool IsSynchronized { ... Read More

How to determine if the string has all unique characters using C#?

Arjun Thakur

Arjun Thakur

Updated on 20-Jun-2020 16:21:24

282 Views

To determine if a string has unique characters or not, firstly check a word in the string with the next word −for (int j = i + 1; j < val.Length; j++) {    if (val[i] == val[j]) }If you find a match, that would mean the string do not ... Read More

Interning of String in C#

Arjun Thakur

Arjun Thakur

Updated on 20-Jun-2020 16:15:42

135 Views

Interning of string optimizes memory and performance.Through this, you can put strings in the runtime's shared string pool.Let us see an example −Example Live Demousing System; using System.Text; public class Demo {    public static void Main() {       string str1 = new StringBuilder().Append("Car is a ").Append("Vehicle").ToString();   ... Read More

How to capture file not found exception in C#?

Arjun Thakur

Arjun Thakur

Updated on 20-Jun-2020 16:09:05

243 Views

The file not found exception is raised when you try to find a file that does not exist.Let’s say I have set a file in StreamReader, “new.txt” that does not exist. If you will try to access it using StreamReader(to read it), it will throw FileNotFoundException −using (StreamReader sReader = ... Read More

Advertisements