Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Programming Articles - Page 3151 of 3363
873 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
446 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
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
440 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; }
179 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
254 Views
The different ways with which a method can be overloaded is −The datatypes of parameters are different The number of parameters are differentThe following gives an example stating different datatypes of parameters −void print(int i) { Console.WriteLine("Printing int: {0}", i ); } void print(double f) { Console.WriteLine("Printing float: {0}" , f); } void print(string s) { Console.WriteLine("Printing string: {0}", s); }The following states the different number of parameters −// two parameters public static int mulDisplay(int one, int two) { return one * two; } // three parameters public static int mulDisplay(int one, int ... Read More
11K+ Views
To delete an elements from a C# array, we will shift the elements from the position the user want the element to delete.Here, first we have 5 elements −int[] arr = new int[5] {35, 50, 55, 77, 98};Now let’s say we need to delete the element at 2nd position i.e. variable “pos = 2” is set, for that shift the elements after the specified position −// Shifting elements for (i = pos-1; i < 4; i++) { arr[i] = arr[i + 1]; }Now display the result as shown in the complete code below.Example Live Demousing System; using System.Collections.Generic; using System.Linq; ... Read More
2K+ Views
IndexOutOfRangeException occurs when you try to access an element with an index that is outsise the bounds of the array.Let’s say the following is our array. It has 5 elements −int [] n = new int[5] {66, 33, 56, 23, 81};Now if you will try to access elements with index more than 5, then the IndexOutOfRange Exception is thrown −for (j = 0; j < 10; j++ ) { Console.WriteLine("Element[{0}] = {1}", j, n[j]); }In the above example, we are trying to access above index 5, therefore the following error occurs −System.IndexOutOfRangeException: Index was outside the bounds of the array.Here ... Read More
2K+ Views
The System.OutOfMemoryException occurs when the CLR fail in allocating enough memory that is needed.System.OutOfMemoryException is inherited from the System.SystemException class.Set the strings −string StudentName = "Tom"; string StudentSubject = "Maths";Now you need to initialize with allocated Capacity that is the length of initial value −StringBuilder sBuilder = new StringBuilder(StudentName.Length, StudentName.Length);Now, if you will try to insert additional value, the exception occurs.sBuilder.Insert(value: StudentSubject, index: StudentName.Length - 1, count: 1);The following exception occurs −System.OutOfMemoryException: Out of memoryTo capture the error, try the following code −Example Live Demousing System; using System.Text; namespace Demo { class Program { static void ... Read More