Programming Articles - Page 2247 of 3366

How to play user modified Beep sound through Console in C#?

AmitDiwan
Updated on 11-Dec-2019 05:29:51

337 Views

To play user modified beep sound through Console, the code is as follows −Example Live Demousing System; public class Demo {    public static void Main(String[] args){       Console.WriteLine("Displaying standard output stream...");       Console.WriteLine("Standard Output Stream = "+Console.Out);       Console.WriteLine("Beep sound through Console");       Console.Beep();       Console.WriteLine("Beep sound through Console with frequence 1000 hertz and duration 500 milliseconds");       Console.Beep(1000, 500);    } }OutputThis will produce the following output −Displaying standard output stream... Standard Output Stream = System.IO.TextWriter+SyncTextWriter Beep sound through Console Beep sound through Console with frequence 1000 ... Read More

How to get the HashCode of the tuple in C#?

AmitDiwan
Updated on 11-Dec-2019 05:26:36

181 Views

To get the HashCode of the tuple, the code is as follows −Example Live Demousing System; public class Demo {    public static void Main(String[] args){       var tuple1 = Tuple.Create(150, 400, 500, 700, 100, 1200, 1500, Tuple.Create(50, 100));       var tuple2 = Tuple.Create(150, 400, 500, 700, 100, 1200, 1500, Tuple.Create(100, 200));       Console.WriteLine("Is Tuple1 equal to Tuple2? = "+tuple1.Equals(tuple2));       Console.WriteLine("HashCode of Tuple1 = "+tuple1.GetHashCode());       Console.WriteLine("HashCode of Tuple2 = "+tuple2.GetHashCode());    } }OutputThis will produce the following output −Is Tuple1 equal to Tuple2? = False HashCode of Tuple1 = ... Read More

How to create a StringCollection in C#?

AmitDiwan
Updated on 11-Dec-2019 05:22:56

128 Views

To create a StringCollection in C#, the code is as follows −Example Live Demousing System; using System.Collections.Specialized; public class Demo {    public static void Main(){       StringCollection strCol = new StringCollection();       String[] strArr = new String[] { "A", "B", "C", "D", "E", "F", "G", "H" };       Console.WriteLine("StringCollection elements...");       foreach (string str in strArr){          Console.WriteLine(str);       }       strCol.AddRange(strArr);       Console.WriteLine("Element at 5th index = "+strCol[5]);       Console.WriteLine("Count of strings in StringCollection = " + strCol.Count);    } ... Read More

How to create a shallow copy of SortedList Object in C#?

AmitDiwan
Updated on 11-Dec-2019 05:10:26

224 Views

To create a shallow copy of SortedList object, the code is as follows −Example Live Demousing System; using System.Collections; public class Demo {    public static void Main(String[] args){       SortedList list = new SortedList();       list.Add("A", "Jacob");       list.Add("B", "Sam");       list.Add("C", "Tom");       list.Add("D", "John");       list.Add("E", "Tim");       list.Add("F", "Mark");       list.Add("G", "Gary");       list.Add("H", "Nathan");       list.Add("I", "Shaun");       list.Add("J", "David");       Console.WriteLine("SortedList elements...");       foreach(DictionaryEntry d in list){     ... Read More

How to play Beep sound through Console in C#?

AmitDiwan
Updated on 11-Dec-2019 05:05:47

273 Views

To play beep sound through Console, the code is as follows −Example Live Demousing System; public class Demo {    public static void Main(String[] args){       Console.WriteLine("Displaying standard output stream...");       Console.WriteLine("Standard Output Stream = "+Console.Out);       Console.WriteLine("Beep sound through Console");       Console.Beep();    } }OutputThis will produce the following output −Displaying standard output stream... Standard Output Stream = System.IO.TextWriter+SyncTextWriter Beep sound through ConsoleExampleLet us now see another example − Live Demousing System; public class Demo {    public static void Main(String[] args){       Console.WriteLine("Displaying standard output stream...");       Console.WriteLine("Standard ... Read More

How to perform a specified action on each element of the List in C#?

AmitDiwan
Updated on 11-Dec-2019 05:03:03

249 Views

To perform a specified action on each element of the List, the code is as follows −Example Live Demousing System; using System.Collections.Generic; public class Demo {    public static void demo(int s){       s = s * 10;       Console.WriteLine(s);    }    public static void Main(String[] args){       List list = new List();       list.Add(25);       list.Add(50);       list.Add(75);       list.Add(100);       list.Add(200);       list.Add(250);       list.Add(275);       list.Add(300);       Console.WriteLine("List...");       foreach (int ... Read More

How to handle an exception using lambda expression in Java?

raja
Updated on 10-Jul-2020 12:01:45

3K+ Views

A lambda expression body can't throw any exceptions that haven't specified in a functional interface. If the lambda expression can throw an exception then the "throws" clause of a functional interface must declare the same exception or one of its subtype.Exampleinterface Student {    void studentData(String name) throws Exception; } public class LambdaExceptionTest {    public static void main(String[] args) {       // lamba expression        Student student = name -> {          System.out.println("The Student name is: " + name);          throw new Exception();       };       try {          student.studentData("Adithya");       } catch(Exception e) {       }    } }OutputThe Student name is: Adithya

How to insert the elements of a collection into the List at the specified index in C#?

AmitDiwan
Updated on 10-Dec-2019 12:27:32

290 Views

To insert the elements of a collection into the List at the specified index, the code is as follows −Example Live Demousing System; using System.Collections.Generic; public class Demo {    public static void Main(String[] args){       string[] strArr = { "John", "Tom", "Kevin", "Mark", "Gary" };       List list = new List(strArr);       Console.WriteLine("Elements in a List...");       foreach(string str in list){          Console.WriteLine(str);       }       strArr = new string[] { "Demo", "Text" };       Console.WriteLine("Inserted new elements in a range...");     ... Read More

How to get TypeCode in C#?

AmitDiwan
Updated on 10-Dec-2019 12:25:28

193 Views

To get TypeCode in C#, the code is as follows −Example Live Demousing System; public class Demo {    public static void Main(){       string s = "Demo";       Console.WriteLine("String = " +s);       Console.WriteLine("String Type = " +s.GetType());       Console.WriteLine("GetTypeCode = " +s.GetTypeCode());    } }OutputThis will produce the following output −String = Demo String Type = System.String GetTypeCode = StringExampleLet us now see another example − Live Demousing System; public class Demo {    public static void Main(){       int i = 100;       double d = 5.26d; ... Read More

How to get the Standard Input and Output Stream through Console in C#?

AmitDiwan
Updated on 10-Dec-2019 12:23:12

417 Views

To get the standard input stream through Console, the code is as follows −Example Live Demousing System; public class Demo {    public static void Main(string[] args){       Console.WriteLine("Displaying standard input stream...");       Console.WriteLine("Standard Input Stream = "+Console.In);    } }OutputThis will produce the following output −Displaying standard input stream... Standard Input Stream = System.IO.TextReader+SyncTextReaderExampleLet us now see an example to display standard output stream − Live Demousing System; public class Demo {    public static void Main(string[] args){       Console.WriteLine("Displaying standard output stream...");       Console.WriteLine("Standard Output Stream = "+Console.Out);    } }OutputThis will ... Read More

Advertisements