Array IsSynchronized Property of Array Class in C#

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

180 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 { get; }The Array.IsSynchronized property implementation is the same like the SyncRoot property −Example Live Demousing System; using System.Collections.Generic; using System.Linq; class Program {    static void Main() {       Array arr = new int[] { 2, 1, 9, 4, 8, 6,8 };       lock(arr.SyncRoot) {          foreach (Object val in arr)          Console.WriteLine(val);       }    } }Output2 1 9 4 8 6 8

Determine If a String Has All Unique Characters Using Chash

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

441 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 have unique characters.If you are unable to find a match, then the string has all unique characters.In case of a match, return false i.e. unique characters not found −for (int j = i + 1; j < val.Length; j++) {    if (val[i] == val[j])    return false; }

Use ReadKey Method of Console Class in C#

George John
Updated on 20-Jun-2020 16:19:06

2K+ Views

Console.ReadKey(); is for the VS.NET Users. This makes the program wait for a key press and it prevents the screen from running and closing quickly when the program is launched from Visual Studio .NET.A common use of the ReadKey() method is that you can halt the program execution. This could be done until a key is pressed by the user.Let us see an example −Example Live Demousing System; public class Demo {    public static void Main() {       DateTime date = DateTime.Now;       TimeZoneInfo timeZone = TimeZoneInfo.Local;       Console.WriteLine("Time Zone = {0}", timeZone.IsDaylightSavingTime(date) ... Read More

Integer Literals vs Floating Point Literals in C#

Chandu yadav
Updated on 20-Jun-2020 16:16:35

451 Views

Integer LiteralsAn 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. Here are some of the examples of integer literals −10 // int 18u // unsigned intLet’s use the above literal while declaring and initializing a variable −// int int a =10;We will now print the values −Example Live Demousing System; namespace Demo {    class Program {       static void Main(string[] args) {          // int          int a =200;   ... Read More

Interning of String in C#

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

219 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();       // Interned string       string str2 = string.Intern(str1);       Console.WriteLine("Interned String"+str2);    } }OutputInterned StringCar is a VehicleHere, we can see Interned string −string str2 = string.Intern(str1);

HashSet in C#

George John
Updated on 20-Jun-2020 16:13:36

877 Views

HashSet in C# eliminates duplicate strings or elements in an array.In C#, it is an optimized set collection.Let us see an example to remove duplicate strings using C# HashSet. Here, we have duplicate elements −Example Live Demousing System; using System.Collections.Generic; using System.Linq; class Program {    static void Main() {       string[] arr1 = {          "bus",          "truck",          "bus",          "car",          "truck"       };       Console.WriteLine(string.Join(", ", arr1));       // HashSet ... Read More

C++ Features Missing in C#

Chandu yadav
Updated on 20-Jun-2020 16:12:29

262 Views

C# is a simple, modern, general-purpose, object-oriented programming language developed by Microsoft within its .NET initiative led by Anders Hejlsberg.C++ is a middle-level programming language developed by Bjarne Stroustrup starting in 1979 at Bell Labs. C++ runs on a variety of platforms, such as Windows, Mac OS, and the various versions of UNIX.The following are some of the features of C++ missing in C# −In C#, Multiple Inheritance is not possible, whereas C++ can easily implement Multiple Inheritance.In C++, you need to manage memory manually and must allocate and deallocate memory for your objects.C++ can create standalone applications, whereas C# ... Read More

Computer Storage Definitions and Notations

Alex Onsman
Updated on 20-Jun-2020 16:11:08

2K+ Views

Computer storage contains many components that are used to store computer data. Some information about the various storage devices is given below.Computer Storage DefinitionsThe computer storage devices include Primary and Secondary Storage devices. These are explained in detail as follows −Primary Storage DevicesPrimary storage is also known as the main memory and is the memory directly accessible by the CPU. Some primary storage devices are −ROMROM is read only memory. This memory cannot be changed, it can only be read as required. Since ROM is unchangeable memory, it is used by data and programs that are frequently required and seldom ... Read More

Trigonometric Functions in C#

Chandu yadav
Updated on 20-Jun-2020 16:10:23

3K+ Views

Trignometric Functions in C# include, ACos, ASin, Sin, Cos, Tan, etc. It comes under the Math type of the System namespace.The following is an example showing how to implement trigonometric functions in C# −Example Live Demousing System; class Program {    static void Main() {       Console.WriteLine(Math.Acos(0));       Console.WriteLine(Math.Cos(2));       Console.WriteLine(Math.Asin(0.2));       Console.WriteLine(Math.Sin(2));       Console.WriteLine(Math.Atan(-5));       Console.WriteLine(Math.Tan(1));    } }Output1.5707963267949 -0.416146836547142 0.201357920790331 0.909297426825682 -1.37340076694502 1.5574077246549Above we saw the Inverse Sine value using Asin −Math.Asin(0.2)With that, we also saw the Inverse Cosine value using Acos −Math.Acos(0)In the ... Read More

Capture File Not Found Exception in C#

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

413 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 = new StreamReader("new.txt")) { sReader.ReadToEnd(); }To handle it, you need to use try and catch −Try {    using (StreamReader sReader = new StreamReader("new.txt")) {       sReader.ReadToEnd();    }    }catch (FileNotFoundException e) {       Console.WriteLine("File Not Found!");       Console.WriteLine(e);    }

Advertisements