Found 33676 Articles for Programming

Keywords in C#

George John
Updated on 22-Jun-2020 08:58:35

689 Views

Keywords are reserved words predefined to the C# compiler. These keywords cannot be used as identifiers. However, if you want to use these keywords as identifiers, you may prefix the keyword with the @ character.The following are the two types of keywords in C#.Reserved KeywordsabstractasbaseBoolbreakbytecasecatchcharcheckedClassconstcontinuedecimaldefaultdelegatedoDoubleelseenumeventexplicitexternfalseFinallyfixedfloatforforeachgotoifImplicitinin (generic modifier)intinterfaceinternalisLocklongnamespacenewnullobjectoperatorOutout (generic modifier)overrideparamsprivateprotectedpublicReadonlyrefreturnsbytesealedshortsizeofstackallocstaticstringstructswitchthisthrowTruetrytypeofuintulonguncheckedunsafeUshortusingvirtualvoidvolatilewhileContextual Keywordsaddaliasascendingdescendingdynamicfromgetglobalgroupintojoinletorderbypartial (type)partial(method)removeselectset

Large Fibonacci Numbers in C#

Chandu yadav
Updated on 22-Jun-2020 08:33:12

476 Views

To display large Fibonacci numbers, try the following login and code.Here, we have set the value of n as the series. Set it to get the Fibonacci number. Below, we have set it to 100 to get the first 100 Fibonacci numbers.Since the first two numbers in a Fibonacci series are 0 and 1. Therefore, we will set the first two values.int val1 = 0, val2 = 1;The following is the complete code to display large Fibonacci numbers.Example Live Demousing System; public class Demo {    public static void Main(string[] args) {       int val1 = 0, val2 = ... Read More

How to print all the Armstrong Numbers from 1 to 1000 using C#?

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

452 Views

To display Armstrong numbers from 1 to 100, firstly use a while loop.Examplewhile (val

Quickly convert Decimal to other bases in C#

Ankith Reddy
Updated on 22-Jun-2020 08:37:39

699 Views

To quickly convert decimal to other bases, use Stacks. Let us see an example.Firstly, I have set the variable “baseNum” as 2int baseNum = 2;In the same way, if you want another base, then −// base 8 int baseNum = 8; // base 10 int baseNum = 10;After getting the value, set a stack and get the values by getting the remainder and other calculations as shown below.Here, n is the decimal number.Stack s = new Stack(); do {    s.Push(n % baseNum);    n /= baseNum; } while (n != 0);After using the stack, pop out the elements. ... Read More

Print a 2 D Array or Matrix in C#

karthikeya Boyini
Updated on 27-Mar-2020 10:08:56

3K+ Views

First, set a two-dimensional array.int[, ] arr = new int[10, 10];Now, get the elements from the user −for (i = 0; i < m; i++) {    for (j = 0; j < n; j++) {       arr[i, j] = Convert.ToInt16(Console.ReadLine());    } }Let us see the complete example to display the matrix.Example Live Demousing System; using System.Linq; class Demo {    static void Main() {       int m, n, i, j;       // rows and columns of the matrix+       m = 2;       n = ... Read More

How to perform Matrix Addition using C#?

George John
Updated on 22-Jun-2020 08:40:51

1K+ Views

To perform matrix addition, take two matrices. Enter the rows and columns of matrix one and matrix two. Remember, both the matrix should be a square matrix to add them.Now add elements to both the matrices. Declare a new array and add both the arrays in it.arr3[i, j] = arr1[i, j] + arr2[i, j];Let us see the complete code −Exampleusing System; using System.Linq; class Demo {    static void Main() {       int m, n, i, j;           Console.Write("Enter number of rows and columns of the matrix ");       ... Read More

What is the difference between list and dictionary in C#?

Chandu yadav
Updated on 22-Jun-2020 08:20:30

6K+ Views

Dictionary is a collection of keys and values in C#. Dictionary is included in the System.Collection.Generics namespace. Dictionary is a generic type and returns an error if you try to find a key which is not there.List collection is a generic class and can store any data types to create a list.A list is a group of items −List myList = new List() {    "Maths",    "English", "   Science" };Dictionary is a set of key-value pairs.Dictionary d = new Dictionary(); d.Add("squash", 1); d.Add("football", 2); d.Add("rugby", 3);Looping is easier and faster in a list and access element using index ... Read More

Queue Interface In C#

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

456 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

3K+ 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

226 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

Advertisements