Arjun Thakur has Published 1025 Articles

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

Arjun Thakur

Arjun Thakur

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

155 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

419 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

197 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

388 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

How to display Absolute value of a number in C#?

Arjun Thakur

Arjun Thakur

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

3K+ Views

To find the absolute value of a number in C#, use the Math.Abs method.Set numbers first −int val1 = 77; int val2 = -88;Now take two new variables and get the Absolute value of the above two numbers −int abs1 = Math.Abs(val1); int abs2 = Math.Abs(val2);Let us see the complete ... Read More

What is composition in C#?

Arjun Thakur

Arjun Thakur

Updated on 20-Jun-2020 15:54:17

563 Views

If the parent object is deleted under Composition, then the child object also loses its status. The composition is a special type of Aggregation and gives a part-of relationship.For example, A Car has an engine. If the car is destroyed, the engine is destroyed as well.public class Engine {    . ... Read More

What are pointers in C#?

Arjun Thakur

Arjun Thakur

Updated on 20-Jun-2020 15:38:39

6K+ Views

Pointer is a variable whose value is the address of another variable i.e., the direct address of the memory location.The syntax of a pointer is −type *var-name;The following is how you can declare a pointer type −double *z; /* pointer to a double */C# allows using pointer variables in a ... Read More

How to use C# BinaryReader class?

Arjun Thakur

Arjun Thakur

Updated on 20-Jun-2020 15:28:41

190 Views

Use the BinaryReader class if you want to read binary information from the stream.The BinaryReader class is in System.IO namespace.The following is an example showing using the BinaryReader class to read from a file −static void WriteMe() {    using (BinaryWriter w = new BinaryWriter(File.Open("C:\abc.txt", FileMode.Create))) {       ... Read More

How to display the name of the Current Thread in C#?

Arjun Thakur

Arjun Thakur

Updated on 20-Jun-2020 15:08:48

2K+ Views

Use the Name property to display the name of the current thread in C#.Firstly, use the currentThread property to display information about a thread −Thread thread = Thread.CurrentThread;Now use the thread.Name property to display name of the thread −thread.NameLet us see the complete code show current thread’s name in C# ... Read More

How to capture null reference exception in C#?

Arjun Thakur

Arjun Thakur

Updated on 20-Jun-2020 14:54:23

318 Views

It handles errors generated from referencing a null object. The Null reference exception occurs when you are looking to access member fields or function types that points to null.Let’s say we have the following null string −string str = null;Now you try to get the length of the null string, ... Read More

Advertisements