- 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
![Samual Sam](https://www.tutorialspoint.com/assets/profiles/13514/profile/60_83486-1512649303.jpg)
548 Views
ClassClass is a blueprint for a data type. A class definition starts with the keyword class followed by the class name.StructA structure is a value type data type. It helps you to make a single variable hold related data of various data types. The struct keyword is used for creating a structure.The following are the differences −Classes are reference types and structs are value typesStructures do not support inheritanceStructures cannot have default constructorWhen you create a struct object using the new operator, it gets created and the appropriate constructor is called. Unlike classes, structs can be instantiated without using the ... Read More
![karthikeya Boyini](https://www.tutorialspoint.com/assets/profiles/13518/profile/60_31598-1537784993.jpg)
730 Views
To implement Remove() and RemoveAt() methods in C#, try the following code −Firstly, set a list.List myList = new List() { "mammals", "reptiles", "amphibians", "vertebrate" };Now, use Remove() method to remove an element.myList.Remove("reptiles");Now, use RemoveAt() method to remove an element by setting the position.myList.RemoveAt(2);The following is the complete code −Exampleusing System; using System.Collections.Generic; using System.Linq; class Program { static void Main() { List myList = new List() { "mammals", "reptiles", "amphibians", "vertebrate" ... Read More
![George John](https://www.tutorialspoint.com/assets/profiles/13511/profile/60_58410-1512537824.png)
72 Views
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. For example, assign the values like the following statement −double[] price = new double[5]; price[0] = 3245.50; price[1] = 1234.50; price[2] = 8765.50; price[3] = 5784.50; price[4] = 6576.50;We assigned five values above to the price array. You can assign values to the array at the time of declaration.double[] price = new double[5] {3245.50, 1234.50, 8765.50, 6576.50;};
![Samual Sam](https://www.tutorialspoint.com/assets/profiles/13514/profile/60_83486-1512649303.jpg)
3K+ Views
Java has a final keyword, but C# does not have its implementation. Use the sealed or readonly keyword in C# for the same implementation.The readonly would allow the variables to be assigned a value only once. A field marked "read-only", can only be set once during the construction of an object. It cannot be changed.Exampleclass Employee { readonly int age; Employee(int age) { this.age = age; } void ChangeAge() { //age = 27; // Compile error } }Above, we have set the age field as readonly, which once assigned cannot be changed.
![Chandu yadav](https://www.tutorialspoint.com/assets/profiles/22330/profile/60_142811-1519038104.jpg)
177 Views
HashSet in C# eliminates duplicate strings or elements in an array.In C#, it is an optimized set collection.Let us see an example to remove duplicate strings using C# HashSet −Exampleusing System; using System.Collections.Generic; using System.Linq; class Program { static void Main() { string[] arr1 = { "one", "two", "two", "one", "three" }; Console.WriteLine(string.Join(",", arr1)); // HashSet var h = new HashSet(arr1); // eliminates duplicate words string[] arr2 = h.ToArray(); Console.WriteLine(string.Join(",", arr2)); } }To declare HashSet.var h = new HashSet
![Ankith Reddy](https://www.tutorialspoint.com/assets/profiles/22328/profile/60_142162-1519038074.jpg)
458 Views
Firstly, set the original array −int[] arr = { 1, 2,3 }; // Original Array Console.WriteLine("Original Array= "); fo reach (int i in arr) { Console.WriteLine(i); }Now, use the Array.reverse() method to reverse the array −Array.Reverse(arr);The following is the complete code to reverse an array in C# −Exampleusing System; class Demo { static void Main() { int[] arr = { 9, 32, 87, 45, 77, 56 }; // Original Array Console.WriteLine("Original Array= "); foreach (int i in arr) { Console.WriteLine(i); } // Reverse Array Array.Reverse(arr); Console.WriteLine("Reversed Array= "); foreach (int j in arr) { Console.WriteLine(j); } Console.ReadLine(); } }
![karthikeya Boyini](https://www.tutorialspoint.com/assets/profiles/13518/profile/60_31598-1537784993.jpg)
3K+ Views
Java has a final keyword, but C# does not have its implementation. For the same implementation, use the sealed keyword.With sealed, you can prevent overriding of a method. When you use sealed modifiers in C# on a method, then the method loses its capabilities of overriding. The sealed method should be part of a derived class and the method must be an overridden method.The following example won’t allow you to override the method display() because it has a sealed modifier for the ClassTwo derived class.ClassOne is our base class, whereas ClassTwo and ClassThree are derived classes −Exampleclass ClassOne { ... Read More
![Samual Sam](https://www.tutorialspoint.com/assets/profiles/13514/profile/60_83486-1512649303.jpg)
805 Views
Arrays were a pointer to an address in memory of the index. This index was the 1st element of the array. Here, the index is like an offset and the concept even before C language originated.Let’s say your array elements begins from 0Xff000 and has 5 elements like {35, 23, 67, 88, 90}. Therefore, you array in memory would be like the following because int is stored using 4 bytes.0Xff000 has 35 0Xff004 has 23 0Xff008 has 67 0Xff012 has 88 0Xff016 has 90That would mean when the array is accessed, zero offsets would be index 0.Let us further see ... Read More
![Arjun Thakur](https://www.tutorialspoint.com/assets/profiles/13574/profile/60_74441-1560315595.jpg)
316 Views
Tuple comparison came after C# 7.3.Easily compare two tuples using the equality operator in C#.Let’s say we have two tuples −var one = (x: 1, y: 2); var two = (p: 1, 2: 3, r: 3, s:4);To compare them, just use the == operator −if (one == two) Console.WriteLine("Both the tuples are same (values are same).");Let use see the code −Examplevar one = (x: 1, y: 2); var two = (p: 1, 2: 3, r: 3, s:4); if (one == two) Console.WriteLine("Both the tuples are same (values are same)."); lse Console.WriteLine("Both the tuples values are not same.");