Found 34494 Articles for Programming

Sorting a HashMap according to keys in C#

Chandu yadav
Updated on 22-Jun-2020 08:28:50

5K+ Views

HashMap is in Java, not C#. The equivalent of HashMap in C# is Dictionary that is used as a collection of key-value pair.Firstly, set the Dictionary −Dictionary d = new Dictionary(); d.Add("soccer", 1); d.Add("cricket", 2); d.Add("tennis", 3); d.Add("rugby", 4);Now get the keys and sort them using ToList() and Sort() method respectively.// get keys var val = d.Keys.ToList(); // sort val.Sort();The following is the complete example to sort a HashMap according to keys −Exampleusing System; using System.Collections.Generic; using System.Linq; class Program {    static void Main() {       Dictionary d = new Dictionary()     ... Read More

Medium-Earth Orbit Satellites

Samual Sam
Updated on 03-Aug-2019 19:32:16

1K+ Views

Medium earth orbit (MEO) satellites lie between the two Van Allen Belts. MEOs are also called Intermediate Circular Orbits (ICOs).The altitudes of these satellites range from 2, 000 km to 35, 000 km, i.e. above the low earth orbits and below the geosynchronous orbits. The orbital periods of MEOs range from 2 hours to more than 23 hours, depending upon their attitudes.Types of MEOs according to orbitsMEOs with circular orbits − They revolve at constant speed at an constant altitude.MEOs with elliptical orbits − Lowest altitude is called perigee and the speed is highest here. Highest altitude is called apogee ... Read More

String Join() method

karthikeya Boyini
Updated on 27-Mar-2020 09:40:42

493 Views

The Join () method in strings concatenates all the elements of a string array, using the specified separator between each element.In the below example we have a multi-line string and we have set the separator as “” −String.Join("", starray);ExampleThe following is the complete example − Live Demousing System; namespace StringApplication {    class StringProg {       static void Main(string[] args) {          string[] starray = new string[]{"Down the way nights are dark",             "And the sun shines daily on the mountaintop",             "I took ... Read More

Retrieve data value as a pointer in C#

Chandu yadav
Updated on 22-Jun-2020 07:50:46

581 Views

A pointer is a variable whose value is the address of another variable. Retrieve the data stored at the located referenced by the pointer variable, using the ToString() method.ExampleHere in an example −using System; namespace UnsafeCodeApplication {    class Program {       public static void Main() {          unsafe {             int var = 100;             int* p = &var;             Console.WriteLine("Data is: {0} " , var);             Console.WriteLine("Data is: {0} " , p->ToString());             Console.WriteLine("Address is: {0} " , (int)p);          }          Console.ReadKey();       }    } }OutputAbove will require you to set unsafe comman line option. After seeting it, the following output would be visible.Data is: 100 Data is: 100 Address is: 77678547

Abort in C#

Samual Sam
Updated on 22-Jun-2020 07:52:56

485 Views

The Abort() method is used for destroying threads.The runtime aborts the thread by throwing a ThreadAbortException. This exception cannot be caught, the control is sent to the finally block if any.Use the Abort() method on a thread −childThread.Abort();Example Live Demousing System; using System.Threading; namespace MultithreadingApplication {    class ThreadCreationProgram {       public static void CallToChildThread() {          try {             Console.WriteLine("Child thread starts");             // do some work, like counting to 10             for (int counter = 0; counter

Difference between TrimStart() and TrimEnd() in C#

Arjun Thakur
Updated on 22-Jun-2020 07:53:25

540 Views

TrimStart() method removes all leading occurrences of a set of characters, whereas TrimEnd()removes all trailing occurrences of a set of characters.TrimStart()The TrimStart() method removes all leading occurrences of a set of characters specified in an array.Let us see an example to remove all leading zeros −Example Live Demousing System; class Program {    static void Main() {       String str ="0009678".TrimStart(new Char[] { '0' } );       Console.WriteLine(str);    } }Output9678TrimEnd()The TrimEnd() method removes all trailing occurrences of a set of characters specified in an array.Let us see an example to remove all trailing 1s −Example Live ... Read More

What is the difference between pass by value and reference parameters in C#?

karthikeya Boyini
Updated on 30-Jul-2019 22:30:23

536 Views

Reference Parameters A reference parameter is a reference to a memory location of a variable. The reference parameters represent the same memory location as the actual parameters that are supplied to the method. When you pass parameters by reference, unlike value parameters, a new storage location is not created for these parameters. Pass by Value This is the default mechanism for passing parameters to a method. In this mechanism, when a method is called, a new storage location is created for each value parameter. The values of the actual parameters are copied into them. Hence, the changes made to the ... Read More

What is the difference between overriding and hiding in C#?

Ankith Reddy
Updated on 30-Jul-2019 22:30:23

1K+ Views

Method hiding is also called shadowing in C#. The method of the parent class is available to the child class without using the override keyword in shadowing. The child class has its own version of the same function. Define a behavior that is specific to the subclass type in overriding, you, which means a subclass can implement a parent class method based on its requirement. Hiding redefines the complete method, whereas overriding redefines only the implementation of the method. In Overriding, you can access the base class using the child class’ object overridden method.. Shadowing has cannot access the ... Read More

What is the difference between Read() and ReadLine() methods in C#?

George John
Updated on 22-Jun-2020 07:40:15

542 Views

Read()The Read() reads the next characters from the standard input stream. If a key is pressed on the console, then it would close.int a = Console.Read() Console.WriteLine(a);ReadLine()It reads the next line of characters from the standard input stream.Example Live Demousing System; class Program {    static void Main() {       int x = 10;       Console.WriteLine(x);       Console.Write("Press any key to continue... ");       Console.ReadLine();    } }Output10 Press any key to continue...

What is the difference between initialization and assignment of values in C#?

Chandu yadav
Updated on 30-Jul-2019 22:30:23

860 Views

Let us understand the difference between initialization and assignment of values. Declaring an array. int [] n // declaring Initialization Declaring an array does not initialize the array in the memory. When the array variable is initialized, you can assign values to the array. Array is a reference type, so you need to use the new keyword to create an instance of the array. int n= new int[10]; // initialization Let’s assign value. You can assign values to individual array elements, by using the index number − n[0] = 100; n[1] = 200 ... Read More

Advertisements