- 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 34494 Articles for Programming
![karthikeya Boyini](https://www.tutorialspoint.com/assets/profiles/13518/profile/60_31598-1537784993.jpg)
478 Views
The NameValueCollection sets more than one value for a single key. Now let us see how to use them in our C# program.Set the collection −static NameValueCollection GetCollection() { NameValueCollection myCollection = new NameValueCollection(); myCollection.Add("Tim", "One"); myCollection.Add("John", "Two"); myCollection.Add("Jamie", "Three"); return myCollection; }Now with the GetCollection() method use the “AllKeys” method property to display all the keys −NameValueCollection myCollection = GetCollection(); foreach (string key in myCollection.AllKeys) { Console.WriteLine(key); }
![Samual Sam](https://www.tutorialspoint.com/assets/profiles/13514/profile/60_83486-1512649303.jpg)
583 Views
Use the LINQ orderby keyword to sort a list in C#.In the below example, we have set the orderby for the elements −var myLen = from element in myList orderby element.Length select element;Let us see an example −Example Live Demousing System; using System.Collections.Generic; using System.Linq; class Demo { static void Main() { List myList = new List(); myList.Add("truck"); myList.Add("bus"); myList.Add("cab"); myList.Add("motorbike"); var myLen = from element in myList orderby element.Length select element; ... Read More
![George John](https://www.tutorialspoint.com/assets/profiles/13511/profile/60_58410-1512537824.png)
482 Views
Language Integrated Query (LINQ) is a Microsoft .NET Framework component and the uniform query syntax in C#. It has a set of method names and extends the language with query expressions.For LINQ in C#, use −using System.Linq;Let us see an example. Here we have used the LINQ computational methods Count and Average to find the count of elements and average of those elements in C# −Example Live Demousing System; using System.Linq; class Demo { static void Main() { int[] arr = { 87, 92, 45, 65, 34, 88 }; Console.WriteLine(arr.Average()); Console.WriteLine(arr.Count()); } }output68.5 6
![karthikeya Boyini](https://www.tutorialspoint.com/assets/profiles/13518/profile/60_31598-1537784993.jpg)
1K+ Views
Object is the base class for all data types in C#. The Object Type is the ultimate base class for all data types in C# Common Type System (CTS). The object is an alias for System.Object class.When a value type is converted to object type, it is called boxing and on the other hand, when an object type is converted to a value type, it is called unboxing.The following is an example showing the usage of object data types −using System; using System.IO; namespace Demo { class objectClass { public int x = 56; ... Read More
![Chandu yadav](https://www.tutorialspoint.com/assets/profiles/22330/profile/60_142811-1519038104.jpg)
6K+ Views
AddRange method in lists adds an entire collection of elements. Let us see an example −Firstly, set a list in C# and add elements −List list = new List(); list.Add(100); list.Add(200); list.Add(300); list.Add(400);Now set an array of elements to be added to the list −// array of 4 elements int[] arr = new int[4]; arr[0] = 500; arr[1] = 600; arr[2] = 700; arr[3] = 800;Use the AddRange() method add the entire collection of elements in the list −list.AddRange(arr);Now let us see the complete code and display the list −using System; using System.Collections.Generic; class Demo { static void ... Read More
![Samual Sam](https://www.tutorialspoint.com/assets/profiles/13514/profile/60_83486-1512649303.jpg)
241 Views
Ternary operator is a Conditional operator in C#. It takes three arguments and evaluates a Boolean expression.For example −y = (z == 1) ? 100 : 180;Above, if the first operand evaluates to true (1), the second operand is evaluated. If the first operand evaluates to false (0), the third operand is evaluated.The following is an example −Exampleusing System; namespace Demo { class Program { static void Main(string[] args) { int x, y; x = 25; y = (x == 25) ? 20 : 30; Console.WriteLine("Value of x = {0}", y); y = (x == 1) ? 50 : 90; Console.WriteLine("Value of y = {0}", y); Console.ReadLine(); } } }Above we have two conditions using the ternary operators −y = (x == 25) ? 20 : 30; y = (x == 1) ? 50 : 90;
![Ankith Reddy](https://www.tutorialspoint.com/assets/profiles/22328/profile/60_142162-1519038074.jpg)
1K+ Views
A namespace inside a namespace is called a nested namespace in C#. This is mainly done to properly structure your code.We have an outer namespace −namespace outer {}Within that, we have an inner namespace inside the outer namespace −namespace inner { public class innerClass { public void display() { Console.WriteLine("Inner Namespace"); } } }Now to call the method of inner namespace, set a class object of the inner class and call the method as shown in the below example −namespace outer { class Program { ... Read More
![Ankith Reddy](https://www.tutorialspoint.com/assets/profiles/22328/profile/60_142162-1519038074.jpg)
631 Views
The object types can be assigned values of any other types, value types, reference types, predefined or user-defined types. However, before assigning values, it needs type conversion.The Object Type is the ultimate base class for all data types in C# Common Type System (CTS). Object is an alias for System.Object class.When a value type is converted to object type, it is called boxing and on the other hand, when an object type is converted to a value type, it is called unboxing.The following is an example −object obj; obj = 100; // this is boxingHere is the complete example showing ... Read More
![Arjun Thakur](https://www.tutorialspoint.com/assets/profiles/13574/profile/60_74441-1560315595.jpg)
1K+ Views
Like any other object-oriented language, C# also has object and classes. Objects are real-world entities and instance of a class. Access the members of the class using an object.To access the class members, you need to use the dot (.) operator after the object name. The dot operator links the name of an object with the name of a member, for example, Box b1 = new Box();Above you can see Box1 is our object. We will use it to access the members −b1.height = 7.0;You can also use it to call member functions −b1.getVolume();The following is an example showing how ... Read More
![Chandu yadav](https://www.tutorialspoint.com/assets/profiles/22330/profile/60_142811-1519038104.jpg)
752 Views
Mixed arrays are a combination of multi-dimension arrays and jagged arrays.Note − The mixed arrays type is obsolete now since .NET 4.0 update removed it.Let us see how you can declare a mixed array −var x = new object[] {89, 45, "jacob", 9.8}We can also set them as −var x = new object[] {87, 33, "tim", 6.7, new List() {"football", "tennis", "squash", “cricket”} }Since, mixed arrays are obslete now. For the same work, use the List collection. Here, we have set int and string in the list −Tuple tuple = new Tuple(60, "John");The same example is displayed below:using System; using ... Read More