- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 34494 Articles for Programming
1K+ Views
Deadlock occurs when a resource is locked by a thread and is required by another thread at the same time. This problem occur frequenty in a multiprocessing system.It can occur when two or more threads wait for a resource that belon to another thread. Here is an example −Thread OneThread TwoTakes Lock PTakes Lock QRequests Lock QRequests Lock PThread One will not get Lock Q since it belongs to Thread Two. In the same way, Thread Two won’t get Lock P since its original owner is Thread One.Deadlocks can also be a three-way deadlock that occurs if three threads and ... Read More
1K+ Views
Set the two dictionaries −Dictionary < string, int > dict1 = new Dictionary < string, int > (); dict1.Add("laptop", 1); dict1.Add("desktop", 2); Dictionary < string, int > dict2 = new Dictionary < string, int > (); dict2.Add("desktop", 3); dict2.Add("tablet", 4); dict2.Add("mobile", 5);Now use HashSet and UnionWith() method to merge the two dictionaries −HashSet < string > hSet = new HashSet < string > (dict1.Keys); hSet.UnionWith(dict2.Keys);Here is the complete code −Exampleusing System; using System.Collections.Generic; class Program { static void Main() { Dictionary < string, int > dict1 = new Dictionary < string, int > (); ... Read More
89 Views
Use the GetDirectories in C# to get a list of sub-folder that appears first −Directory.GetDirectoriesNow loop through those directories and repeat the process for the sub folder.string path = @"d:/New/Myfile"; string[] myDir = Directory.GetDirectories(path, "xml", SearchOption.AllDirectories); Console.WriteLine(myDir.Length.ToString()); foreach (string res in myDir) Console.WriteLine(res);
2K+ Views
System.Collections.Generic namespace is available in C# for LinkedList. The LinkedList class allows insertion and deletion of elements from the list at a fast pace.C# LinkedList class uses the concept of linked list. It allows us to insert and delete elements fastly. It can have duplicate elements. It is found in System.Collections.Generic namespace.Here is an example −Example Live Demousing System; using System.Collections.Generic; class Demo { static void Main() { LinkedList < string > l = new LinkedList < string > (); l.AddLast("one"); l.AddLast("two"); l.AddLast("three"); ... Read More
397 Views
To print “Hello World” in C#, use the Console.WriteLine.Let us see a basic C# program to display a text −Example Live Demousing System; using System.Collections.Generic; using System.Text; namespace Program { class MyApplication { static void Main(string[] args) { Console.WriteLine("Hello World"); Console.Read(); } } }OutputHello WorldAbove, we displayed the text “Hello World” using the WriteLine() method. The output is displayed using the Console −Console.WriteLine("Hello World");
335 Views
Let’s say we need to find that the following string is Palindrome or not −str = "Level";For that, convert the string into character array to chec each character −char[] ch = str.ToCharArray();Now find the reverse −Array.Reverse(ch);Use the Equals method to find whether the reverse is equal to original array or not −bool res = str.Equals(rev, StringComparison.OrdinalIgnoreCase);The following is the complete code −Example Live Demousing System; namespace Demo { class Program { static void Main(string[] args) { string str, rev; str = "Level"; char[] ch ... Read More
295 Views
Let’s say we want to convert the number 48 to binary.Firstly, set it and use the / and % operators and loop until the value is greater than 1 −decVal = 48; while (decVal >= 1) { val = decVal / 2; a += (decVal % 2).ToString(); decVal = val; }Now, display every bit of the binary as shown in the complete code −Example Live Demousing System; using System.Collections.Generic; using System.Text; namespace Demo { class MyApplication { static void Main(string[] args) { int decVal; ... Read More
513 Views
The flow control in try, catch, and finally can be understood using the following example. Here, we are dividing two numbers −Example Live Demousing System; namespace ErrorHandlingApplication { class DivNumbers { int result; DivNumbers() { result = 0; } public void division(int num1, int num2) { try { result = num1 / num2; } catch (DivideByZeroException e) { Console.WriteLine("Exception caught: {0}", e); ... Read More
487 Views
The following states what is an unmanaged code −Applications that are not under the control of the CLR are unmanagedThe unsafe code or the unmanaged code is a code block that uses a pointer variable.The unsafe modifier allows pointer usage in unmanaged code.Here is the module showing how to declare and use a pointer variable. We have used the unsafe modifier here.Let us see the example −Examplestatic unsafe void Main(string[] args) { int var = 20; int* p = &var; Console.WriteLine("Data is: {0} ", var); Console.WriteLine("Address is: {0}", (int)p); Console.ReadKey(); }
151 Views
Boxing is implicit and unboxing is explicit. Unboxing is the explicit conversion of the reference type created by boxing, back to a value type.Let us see an example of variable and object in C# −// int int x = 30; // Boxing object obj = x; // Un boxing int unboxInt = (int) obj;The following is an example showing Un boxing −int x = 5; ArrayList arrList = new ArrayList(); // Boxing arrList.Add(x); // UnBoxing int y = (int) arrList [0];