Programming Articles - Page 2237 of 3366

How to check whether a thread is a background thread or not in C#

AmitDiwan
Updated on 16-Dec-2019 09:53:24

239 Views

To check whether a thread is a background thread or not, the code is as follows −Example Live Demousing System; using System.Threading; public class Demo {    public static void Main() {       Thread thread = new Thread(new ThreadStart(demo1));       ThreadPool.QueueUserWorkItem(new WaitCallback(demo2));       Console.WriteLine("Current state of Thread = "+thread.ThreadState);       Console.WriteLine("ManagedThreadId = "+thread.ManagedThreadId);       Console.WriteLine("Is the Thread a background thread? = "+Thread.CurrentThread.IsBackground);    }    public static void demo1() {       Thread.Sleep(2000);    }    public static void demo2(object stateInfo) {       Console.WriteLine("Thread belongs to managed thread ... Read More

Number of elements in HashSet in C#?

AmitDiwan
Updated on 16-Dec-2019 09:45:47

241 Views

To get the number of elements in HashSet in C#, the code is as follows −Example Live Demousing System; using System.Collections.Generic; public class Demo {    public static void Main() {       HashSet set1 = new HashSet();       set1.Add(25);       set1.Add(50);       set1.Add(75);       set1.Add(100);       set1.Add(125);       set1.Add(150);       Console.WriteLine("Elements in HashSet1");       foreach(int val in set1) {          Console.WriteLine(val);       }       Console.WriteLine("Number of elements in HashSet1 = "+set1.Count);       HashSet set2 ... Read More

Removing the specified node from the LinkedList in C#?

AmitDiwan
Updated on 16-Dec-2019 09:34:53

135 Views

To remove the specified node from the LinkedList, the code is as follows −Example Live Demousing System; using System.Collections.Generic; public class Demo {    public static void Main() {       LinkedList list = new LinkedList();       list.AddLast(100);       list.AddLast(200);       list.AddLast(300);       list.AddLast(400);       list.AddLast(500);       list.AddLast(300);       list.AddLast(500);       Console.WriteLine("LinkedList elements...");       foreach(int i in list) {          Console.WriteLine(i);       }       LinkedListNode val = list.FindLast(300);       Console.WriteLine("Specified value = "+val.Value); ... Read More

Set the bit at a specific position in the BitArray to the specified value in C#?

AmitDiwan
Updated on 16-Dec-2019 09:31:41

195 Views

To set the bit a specific position in the BitArray to the specified values, the code is as follows −Example Live Demousing System; using System.Collections; public class Demo {    public static void Main() {       BitArray arr = new BitArray(5);       arr[0] = true;       arr[1] = false;       arr[2] = true;       arr[3] = false;       Console.WriteLine("BitArray...");       foreach(Object ob in arr) {          Console.WriteLine(ob);       }       arr.Set(2, false);       Console.WriteLine("Updated BitArray...");       ... Read More

ListDictionary Class in C#

AmitDiwan
Updated on 16-Dec-2019 08:11:12

405 Views

The ListDictionary class implements IDictionary using a singly linked list. It is recommended for collections that typically include fewer than 10 items.Following are the properties of ListDictionary class −Sr.NoProperty & Description1CountGets the number of key/value pairs contained in the ListDictionary.2IsFixedSizeGets a value indicating whether the ListDictionary has a fixed size.3IsReadOnlyGets a value indicating whether the ListDictionary is readonly.4IsSynchronizedGets a value indicating whether the ListDictionary is synchronized (thread safe).5Item[Object]Gets or sets the value associated with the specified.6KeysGets an ICollection containing the keys in the ListDictionary.7SyncRootGets an object that can be used to synchronize access to the ListDictionary.8ValuesGets an ICollection containing the ... Read More

How can we write a multiline lambda expression in Java?

raja
Updated on 10-Jul-2020 14:08:21

12K+ Views

Lambda expression is an anonymous method that has used to provide an implementation of a method defined by a functional interface. In Java 8, it is also possible for the body of a lambda expression to be a complex expression or statement, which means a lambda expression consisting of more than one line. In that case, the semicolons are necessary. If the lambda expression returns a result then the return keyword is also required.Syntax([comma seperated argument-list]) -> { multiline statements }Exampleinterface Employee {    String displayName(String s); } public class MultilineLambdaTest {    public static void main(String[] s) {       ... Read More

Index of first occurrence in StringCollection in C#?

AmitDiwan
Updated on 16-Dec-2019 08:03:56

198 Views

To get the index of first occurrence in StringCollection, the code is as follows −Example Live Demousing System; using System.Collections.Specialized; public class Demo {    public static void Main() {       StringCollection strCol = new StringCollection();       strCol.Add("Accessories");       strCol.Add("Books");       strCol.Add("Electronics");       strCol.Add("Books");       Console.WriteLine("StringCollection elements...");       foreach (string res in strCol) {          Console.WriteLine(res);       }       strCol.Insert(2, "Headphone");       Console.WriteLine("StringCollection elements...UPDATED");       foreach (string res in strCol) {          Console.WriteLine(res); ... Read More

Getting an enumerator for the entire ArrayList in C#?

AmitDiwan
Updated on 16-Dec-2019 07:59:23

125 Views

To get an enumerator for the entire ArrayList in C#, the code is as follows −Example Live Demousing System; using System.Collections; public class Demo {    public static void Main(String[] args) {       ArrayList list1 = new ArrayList();       list1.Add("A");       list1.Add("B");       list1.Add("C");       list1.Add("D");       list1.Add("E");       list1.Add("F");       list1.Add("G");       list1.Add("H");       list1.Add("I");       Console.WriteLine("Elements in ArrayList1...");       foreach (string res in list1) {          Console.WriteLine(res);       }   ... Read More

Check whether a SortedList object contains a specific key in C#?

AmitDiwan
Updated on 16-Dec-2019 07:40:32

145 Views

To check whether a SortedList object contains a specific key in C#, the code is as follows −Example Live Demousing System; using System.Collections; public class Demo {    public static void Main() {       SortedList list = new SortedList ();       list.Add("A", "Books");       list.Add("B", "Electronics");       list.Add("C", "Appliances");       list.Add("D", "Pet Supplies");       list.Add("E", "Clothing");       list.Add("F", "Footwear");       Console.WriteLine("Value associated with key E = "+list["E"]);       list["E"] = "HDD";       Console.WriteLine("Value associated with key E [Updated] = "+list["E"]);   ... Read More

How to check whether a List contains the elements that match the specified conditions in C#?

AmitDiwan
Updated on 16-Dec-2019 07:34:49

453 Views

To check whether a List contains the elements that match the specified conditions in C#, the code is as follows −Example Live Demousing System; using System.Collections.Generic; public class Demo {    private static bool demo(int i) {       return ((i % 3) == 0);    }    public static void Main(String[] args) {       List list = new List();       list.Add(255);       list.Add(315);       list.Add(410);       list.Add(500);       list.Add(600);       list.Add(710);       list.Add(800);       list.Add(1000);       Console.WriteLine("List elements...");   ... Read More

Advertisements