Found 2628 Articles for Csharp

Queue Interface In C#

Samual Sam
Updated on 22-Jun-2020 08:45:39

281 Views

Queue represents a first-in, first out collection of object. It is used when you need a first-in, first-out access to items. When you add an item to the list, it is called enqueue, and when you remove an item, it is called deque.Let us see an example of the Queue class.To add elements, use Enqueue −Queue q = new Queue(); q.Enqueue('X'); q.Enqueue('Y'); q.Enqueue('Z');To delete elements, use Dequeue −// remove elements while (q.Count > 0) Console.WriteLine(q.Dequeue());Let us see an example to add elements in a queue.Example Live Demousing System; using System.Collections; namespace Demo {    class Program {     ... Read More

Checked vs Unchecked Exceptions in C#

karthikeya Boyini
Updated on 22-Jun-2020 08:21:35

2K+ Views

You can execute statements in C# in checked or unchecked context.In checked, the exception is raised by arithmetic overflow, whereas in unchecked context, arithmetic overflow is ignored.Checked ExceptionsUse the checked keyword to explicitly enable overflow checking for integral-type arithmetic operations and conversions. For this, just set the checked keyword.Overflow checking can be enabled by compiler options, environment configuration, or use of the checked keyword.res = checked(val + 10);Let’s say the value of val is 2147483647 i.e. the max value of int type. The above will raise an error since it is checked. This enables overflow checking at runtime.Unchecked ExceptionUse the ... Read More

How to perform Multiplication of Exponents of same base using C#?

Arjun Thakur
Updated on 22-Jun-2020 08:21:12

131 Views

Firstly, set the base.double n = 2;Now set the two exponents for division.double e1 = 5; double e2 = 4;Let us see the complete code to get the result of multiplication of exponents of the same base.Example Live Demousing System; class Demo {    static void Main() {       double res, n, e1, e2;       n = 2;       e1 = 5;       e2 = 4;       res = e1 + e2;       Console.WriteLine("Result = {0}^{1} : {2}", n, res, Math.Pow(n, res));       Console.ReadLine();    } }OutputResult = 2^9 : 512

How to pop the first element from a C# List?

Samual Sam
Updated on 31-Oct-2023 04:01:30

26K+ Views

To pop the first element in the list, use the RemoveAt() method. It eliminates the element from the position you want to remove the element.Set the listList myList = new List() {    "Operating System",    "Computer Networks",    "Compiler Design" };Now pop the first element using RemoveAt(0)myList.RemoveAt(0);Let us see the complete example.Example Live Demousing System; using System.Collections.Generic; using System.Linq; class Program {    static void Main() {       List myList = new List() {          "Operating System",          "Computer Networks",          "Compiler Design"       }; ... Read More

How to perform Division of Exponents of Same Base using C#?

Ankith Reddy
Updated on 22-Jun-2020 08:23:13

145 Views

Firstly, set the base −double n = 10;Now set the two exponents for division −double e1 = 10; double e2 = 8;Let us see the complete code to get the result of division of exponents of the same base.Example Live Demousing System; class Demo {    static void Main() {       double res, n, e1, e2;       n = 10;       e1 = 10;       e2 = 8;       res = e1 - e2;       Console.WriteLine("Result = {0}^{1} : {2}", n, res, Math.Pow(n, res));       Console.ReadLine();    } }outputResult = 10^2 : 100

What is a managed code in C#?

karthikeya Boyini
Updated on 22-Jun-2020 08:23:32

278 Views

Managed code is a code whose execution is managed by Common Language Runtime. It gets the managed code and compiles it into machine code. After that, the code is executed.The runtime here i.e. CLR provides automatic memory management, type safety, etc.Managed code is written in high-level languages run on top of .NET. This can be C#, F#, etc. A code compiled in any of this language with their compilers, a machine code is not generated. However, you will get the Intermediate Language code, compiled and executed by runtime.C/C++ code, called "unmanaged code” do not have that privilege. The program is ... Read More

How to call Math Operations using Delegates in C#?

George John
Updated on 22-Jun-2020 08:24:21

229 Views

To understand how to call Math Operations using Delegates in C#, let us see an example wherein we will divide a number.We have a class and a function in it −public class Demo {    public static double DivideFunc(double value) {       return value / 5;    } }Now, our delegate −delegate double myDelegate(double x);Set a value and call −myDelegate[] val = { Demo.DivideFunc }; result(val[0], 20);Math operation is called using delegate −static void result(myDelegate d, double value) {    double result = d(value);    Console.WriteLine("Result = {0}", result); }The above displays the following result for “value/ 5” i.e. 20/5 −Result = 4

Chained Exceptions in C#

Samual Sam
Updated on 22-Jun-2020 08:27:06

393 Views

Chained Exceptions are a chain of try-catch statements that handle exceptions. To create a chain of exceptions i.e. chained exceptions −Set the first try-catch −Examplestatic void Main(string[] args) {    try {       One();    } catch (Exception e) {       Console.WriteLine(e);    } }Now try-catch under method One() −Examplestatic void One() {    try {       Two();    } catch (Exception e) {       throw new Exception("First exception!", e);    } }The method Two() also continues chained exception.Examplestatic void Two() {    try {       Three();    } catch ... Read More

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

Advertisements