- 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)
306 Views
The ToString() method returns a string that represents the current object.In the below example, we have used the ToString() method with another Array class method.arr.GetLowerBound(0).ToString()Example Live Demousing System; using System.Collections.Generic; using System.Linq; using System.Text; namespace lower { class Program { static void Main(string[] args) { Array arr = Array.CreateInstance(typeof(String), 3); arr.SetValue("One", 0); arr.SetValue("Two", 1); Console.WriteLine("Lower Bound {0}",arr.GetLowerBound(0).ToString()); Console.ReadLine(); } } }OutputLower Bound 0
![karthikeya Boyini](https://www.tutorialspoint.com/assets/profiles/13518/profile/60_31598-1537784993.jpg)
176 Views
The Compare method compares two specified string objects and returns an integer that indicates their relative position in the sort order.Firstly, set the strings.string str1 = "Jack"; string str2 = "Mac";Now compare the strings using the Compare() method and if the comparison results 0, then it would mean the strings are equal.String.Compare(str1, str2) == 0Let us see the complete example.Example Live Demousing System; namespace StringApplication { class StringProg { static void Main(string[] args) { string str1 = "Jack"; string str2 = "Mac"; if (String.Compare(str1, str2) ... Read More
![Ankith Reddy](https://www.tutorialspoint.com/assets/profiles/22328/profile/60_142162-1519038074.jpg)
164 Views
The Sort() method sorts the elements in an entire one-dimensional Array using the IComparable implementation of each element of the Array.Set the array.int[] list = { 22, 12, 65, 9};Use the Sort() method to sort the array.Array.Sort(list);The following is an example to learn how to work with the Sort() method.Example Live Demousing System; namespace Demo { class Program { static void Main(string[] args) { int[] list = { 22, 12, 65, 9}; Console.Write("Original Array: "); foreach (int i in list) { ... Read More
![Samual Sam](https://www.tutorialspoint.com/assets/profiles/13514/profile/60_83486-1512649303.jpg)
1K+ Views
The SetValue() method sets a value to the element at the specified position in the one-dimensional Array. The index is specified as a 32-bit integer.Firstly, set the array.Array arr = Array.CreateInstance(typeof(String), 6);No set values to the element using the SetValue() method.arr.SetValue("One", 0); arr.SetValue("Two", 1); arr.SetValue("Three", 3); arr.SetValue("Four", 4); arr.SetValue("Five", 5);The following is an example showing the usage of SetValue() method in C#.Example Live Demousing System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Demo { class Program { static void Main(string[] args) { Array arr = Array.CreateInstance(typeof(String), 6); arr.SetValue("One", 0); ... Read More
![Arjun Thakur](https://www.tutorialspoint.com/assets/profiles/13574/profile/60_74441-1560315595.jpg)
123 Views
Declare Jagged ArrayA Jagged array is an array of arrays. You can declare a jagged array named scores of type int as −int [][] points;Initialize Jagged ArrayLet us now see how to initialize it.int[][] points = new int[][]{new int[]{10, 5}, new int[]{30, 40}, new int[]{70, 80}, new int[]{ 60, 70 }};Access the Jagged Array ElementAccess the jagged array element as.points[i][j]);The following is the complete example showing how to work with jagged arrays in C#.Example Live Demousing System; namespace ArrayApplication { class MyArray { static void Main(string[] args) { int[][] points = new int[][]{new ... Read More
![karthikeya Boyini](https://www.tutorialspoint.com/assets/profiles/13518/profile/60_31598-1537784993.jpg)
7K+ Views
The Reverse() method in array class reverses the sequence of the elements in the entire one-dimensional Array.To reverse an array, just use the Array.Reverse() method −Array.Reverse(temp);Within the reverse method, set the elements like the following code snippet.int[] list = { 29, 15, 30, 98}; int[] temp = list;You can try to run the following code to implement Reverse() method in C#.Example Live Demousing System; namespace Demo { class MyArray { static void Main(string[] args) { int[] list = { 29, 15, 30, 98}; int[] temp = list; ... Read More
![Chandu yadav](https://www.tutorialspoint.com/assets/profiles/22330/profile/60_142811-1519038104.jpg)
1K+ Views
Set the unsorted array first.int[] list = {87, 45, 56, 22, 84, 65};Now use a nested for loop to sort the list, which is passed to a function.for(int i=0; i< arr.Length; i++) { for(int j=i+1; j=arr[j]) { temp=arr[j]; arr[j]=arr[i]; arr[i]=temp; } } Console.Write(arr[i] + " "); }The following is the complete code to sort one-dimensional array in ascending order using non-static method.Example Live Demousing System; namespace Demo { public class MyApplication { public static void Main(string[] args) { ... Read More
![Samual Sam](https://www.tutorialspoint.com/assets/profiles/13514/profile/60_83486-1512649303.jpg)
499 Views
The return statement is used to return value. When a program calls a function, the program control is transferred to the called function. A called function performs a defined task and when its return statement is executed or when its function-ending closing brace is reached, it returns the program control back to the main program.The following is an example to learn about the usage of return statement in C#. Here, we are finding the factorial of a number and returning the result using the return statement.while (n != 1) { res = res * n; n = n ... Read More
![George John](https://www.tutorialspoint.com/assets/profiles/13511/profile/60_58410-1512537824.png)
615 Views
A main method is static since it is available to run when the C# program starts. It is the entry point of the program and runs without even creating an instance of the class.The Main method states what the class does when executed and instantiates other objects and variables.The following shows how to add a Main() method.Exampleusing system; namespace demo { class helloworld { static void main(string[] args) { console.writeline("hello world"); console.readkey(); } } }As you can see in the above example.static void Main(string[] ... Read More
![karthikeya Boyini](https://www.tutorialspoint.com/assets/profiles/13518/profile/60_31598-1537784993.jpg)
10K+ Views
The IndexOf() method of array class in C# searches for the specified object and returns the index of the first occurrence within the entire one-dimensional Array.We have set the array.int[] arr = new int[10]; arr[0] = 100; arr[1] = 200; arr[2] = 300; arr[3] = 400; arr[4] = 500; arr[5] = 600; arr[6] = 700; arr[7] = 800; arr[8] = 900; arr[9] = 1000;Now use the IndexOf() method and set the element for which you want the index, for example, I have set it for element 800.int a = Array.IndexOf(arr, 800);The following is the example showing the usage of IndexOf(, ... Read More