- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 2628 Articles for Csharp
![George John](https://www.tutorialspoint.com/assets/profiles/13511/profile/60_58410-1512537824.png)
175 Views
While declaring a method, if you are not sure of the number of arguments passed as a parameter, then use the C# param arrays.The following is the complete example to learn how to implement param in C# −Exampleusing System; namespace Program { class ParamArray { public int AddElements(params int[] arr) { int sum = 0; foreach (int i in arr) { sum += i; } return sum; } } class Demo { static void Main(string[] args) { ParamArray app = new ParamArray(); int sum = app.AddElements(300, 250, 350, 600, 120); Console.WriteLine("The sum is: {0}", sum); Console.ReadKey(); } } }
![karthikeya Boyini](https://www.tutorialspoint.com/assets/profiles/13518/profile/60_31598-1537784993.jpg)
2K+ Views
Internal keyword allows you to set internal access specifier.Internal access specifier allows a class to expose its member variables and member functions to other functions and objects in the current assembly.Any member with internal access specifier can be accessed from any class or method defined within the application in which the member is defined.Exampleusing System; namespace RectangleApplication { class Rectangle { internal double length; internal double width; double GetArea() { return length * width; } public ... Read More
![Chandu yadav](https://www.tutorialspoint.com/assets/profiles/22330/profile/60_142811-1519038104.jpg)
5K+ Views
There are two types of collections in C#: non-generic collections and generic collections.Generics in C#Generic collections hold elements of same datatypes.For example −ListDictionaryHashsetDictionary − Dictionary is a collection of keys and values in C#. Dictionary is included in the System.Collection.Generics namespace.Hashset − HashSet in C# eliminates duplicate strings or elements in an array.In C#, it is an optimized set collection.Non-Generics in C#Non-generic collections hold elements of different datatypes.The following are the non-generic collections: ArrayList, BitArray.ArrayList − It represents ordered collection of an object that can be indexed individually. ArrayList is an alternative to an array. However, unlike array you ... Read More
![Samual Sam](https://www.tutorialspoint.com/assets/profiles/13514/profile/60_83486-1512649303.jpg)
91 Views
Numeric promotion is the promotion of smaller types to larger types like short to int.In the below example, we have seen a numeric promotion in Conditional Expression.The short types are automatically promoted to larger type int.Exampleusing System; class Program { static void Main() { short val1 = 99; int val2; val2 = (val1 == 1) ? 100 : 30; Console.WriteLine(val2); } }OutputAbove, we have used a conditional expression that automatically promoted to int −val2 = (val1 == 1) ? 100 : 30;Here, val2 is an int and val is a short.
![karthikeya Boyini](https://www.tutorialspoint.com/assets/profiles/13518/profile/60_31598-1537784993.jpg)
384 Views
For multiple-base conversions, set a variable and add the base you want to calculate.Here, for our example, I have set the variable baseNum as 2 −int baseNum = 2;In the same way, if you want base 8, then set the above as −int baseNum = 2; You can also get the above variable value as user input.After getting the value, set a stack and get the values −Stack s = new Stack(); do { s.Push(n % baseNum); n /= baseNum; } while (n != 0);After using the stack, pop out the elements. That would give you the result.Let’s say the ... Read More
![Arjun Thakur](https://www.tutorialspoint.com/assets/profiles/13574/profile/60_74441-1560315595.jpg)
251 Views
Numeric promotion as the name suggests is the promotion of smaller types to larger types like short to int.In the below example, we have seen numeric promotion in Arithmetic Operator multiply.The short types are automatically promoted to larger types −Exampleusing System; class Program { static void Main() { short val1 = 99; ushort val2 = 11; int res = val1 * val2; Console.WriteLine(res); } }
![Arjun Thakur](https://www.tutorialspoint.com/assets/profiles/13574/profile/60_74441-1560315595.jpg)
1K+ Views
The following is the difference between a static and non-static class −Non-static classes can be instantiated, whereas static classes cannot be instantiated i.e. you cannot use the new keyword to create a variable of the class typeStatic classes can only have static methods.Non-static classes can have instance method and static methods.ou access the members of a static class by using the class name itselfStatic class is sealed.Example of static class −public static class CalculateExample of non-static class −public class Calculate
![Samual Sam](https://www.tutorialspoint.com/assets/profiles/13514/profile/60_83486-1512649303.jpg)
1K+ Views
Multi-dimensional arrayMulti-dimensional arrays are also called rectangular array. You can define a 3-dimensional array of integer as −int [ , , ] val;Let us see how to define a two-dimensional array.int[,] val = new[3,3] Jagged arrayA Jagged array is an array of arrays. To access an element from it, just mention the index for that particular array.Here, we have a jagged array with 5 array of integers −int[][] a = new int[][]{new int[]{0,0},new int[]{1,2}, new int[]{2,4},new int[]{ 3, 6 }};
![George John](https://www.tutorialspoint.com/assets/profiles/13511/profile/60_58410-1512537824.png)
362 Views
List collection is a generic class and can store any data types to create a list. To define a List −List l = new List();To set elements in a list, you need to use the Add method.l.Add("One"); l.Add("Two"); l.Add("Three");An array stores a fixed-size sequential collection of elements of the same type.To define Arrays −int[] arr = new int[5]; To initialize and set elements to Arrays −int[] arr = new int[5] {4, 8,5};
![karthikeya Boyini](https://www.tutorialspoint.com/assets/profiles/13518/profile/60_31598-1537784993.jpg)
596 Views
To copy a C# list collection to an array, firstly set a list −List list1 = new List (); list1.Add("One"); list1.Add("Two"); list1.Add("Three"); list1.Add("Four");Now declare a string array and use the CopyTo() method to copy −string[] arr = new string[20]; list1.CopyTo(arr);Let us see the complete code to copy a list into a one – dimensional array.Exampleusing System; using System.Collections.Generic; using System.Linq; public class Demo { public static void Main() { List list1 = new List (); list1.Add("One"); list1.Add("Two"); list1.Add("Three"); list1.Add("Four"); ... Read More