- 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
![Chandu yadav](https://www.tutorialspoint.com/assets/profiles/22330/profile/60_142811-1519038104.jpg)
41 Views
The following is the string array −string[] str = { "Java", "AngularJS", "Python", "jQuery", "HTML5" };Firstly, join it −string.Join(" ", str);Now to separate the above joined strings, use the Split() method as shown in the following code −Example Live Demousing System; public class Demo { public static void Main() { string[] str = { "Java", "AngularJS", "Python", "jQuery", "HTML5" }; // join words string res = string.Join(" ", str); Console.WriteLine("Joined Strings... "+res); string[] convert = res.Split(' '); Console.WriteLine("Separate Joined Strings..."); ... Read More
![Arjun Thakur](https://www.tutorialspoint.com/assets/profiles/13574/profile/60_74441-1560315595.jpg)
182 Views
Declare a string and add elements −string[] str = { "One", "Two", "Three", "Four", "Five" };Use the Join() method to join the words−string res = string.Join(" ", str);Let us see the complete code −Example Live Demousing System; public class Demo { public static void Main() { string[] str = { "One", "Two", "Three", "Four", "Five" }; // join words string res = string.Join(" ", str); Console.WriteLine(res); } }OutputOne Two Three Four Five
![Ankith Reddy](https://www.tutorialspoint.com/assets/profiles/22328/profile/60_142162-1519038074.jpg)
472 Views
Declare and initialize an array −string[] str = new string[] { "Cat", "Mat", "Rat" };Now, ue IndexOf() method to find the index of the word “Mat” −Array.IndexOf(str, "Mat");The following is the code −Example Live Demousing System; public class Demo { public static void Main() { string[] str = new string[] { "Cat", "Mat", "Rat" }; Console.WriteLine("Our Array ="); for (int i = 0; i < str.Length; i++) { string res = str[i]; Console.WriteLine(res); } int findIndex = Array.IndexOf(str, "Mat"); Console.Write("Element Mat found at the following index: "); Console.WriteLine(findIndex); } }OutputOur Array = Cat Mat Rat Element Mat found at the following index: 1
![George John](https://www.tutorialspoint.com/assets/profiles/13511/profile/60_58410-1512537824.png)
3K+ Views
To create an empty string array −string[] str = new string[] {};Above, we haven’t added elements to the array, since it is empty.Even if we will loop though the array, it won’t display anything as shown below −Example Live Demousing System; public class Demo { public static void Main() { string[] str = new string[] {}; Console.WriteLine("String Array elements won't get displayed since it's empty..."); for (int i = 0; i < str.Length; i++) { string res = str[i]; Console.WriteLine(res); } } }OutputString Array elements won't get displayed since it's empty...
![Chandu yadav](https://www.tutorialspoint.com/assets/profiles/22330/profile/60_142811-1519038104.jpg)
2K+ Views
Create a string array −string[] str = new string[] { "Videos", "Tutorials", "Tools", "InterviewQA" };Loop until the length of the array −for (int i = 0; i < str.Length; i++) { string res = str[i]; Console.WriteLine(res); }Here is the complete code −Example Live Demousing System; public class Demo { public static void Main() { string[] str = new string[] { "Videos", "Tutorials", "Tools", "InterviewQA" }; Console.WriteLine("String Array..."); for (int i = 0; i < str.Length; i++) { string res = str[i]; Console.WriteLine(res); } } }OutputString Array... Videos Tutorials Tools InterviewQA
![karthikeya Boyini](https://www.tutorialspoint.com/assets/profiles/13518/profile/60_31598-1537784993.jpg)
3K+ Views
Firstly, set an array −string[] str = new string[]{ "Java", "HTML", "jQuery", "JavaScript", "Bootstrap" };To get the value of the last element, get the length and display the following value −str[str.Length - 1]The above returns the last element.Here is the complete code −Example Live Demousing System; public class Demo { public static void Main() { string[] str = new string[] { "Java", "HTML", "jQuery", "JavaScript", "Bootstrap" }; Console.WriteLine("Array..."); foreach(string res in str) { Console.WriteLine(res); } Console.WriteLine("Last element: "+str[str.Length - 1]); } }OutputArray... Java HTML jQuery JavaScript Bootstrap Last element: Bootstrap
![karthikeya Boyini](https://www.tutorialspoint.com/assets/profiles/13518/profile/60_31598-1537784993.jpg)
9K+ Views
Call a method under Join method to join words −string.Join(" ", display())Now set a string array −string[] str = new string[5];Add individual elements −str[0] = "My"; str[1] = "name"; str[2] = "is"; str[3] = "Brad"; str[4] = "Pitt";And return the same string array from method −return str;The following is the complete code −Example Live Demousing System; public class Demo { public static void Main() { Console.WriteLine(string.Join(" ", display())); } static string[] display() { string[] str = new string[5]; // string array elements str[0] = "My"; str[1] = "name"; str[2] = "is"; str[3] = "Brad"; str[4] = "Pitt"; return str; } }OutputMy name is Brad Pitt
![Samual Sam](https://www.tutorialspoint.com/assets/profiles/13514/profile/60_83486-1512649303.jpg)
217 Views
Use ReadToEnd() method to read the contents of a file in a string.Set it under StreamReader and read the file −using (StreamReader sr = new StreamReader("new.txt")){ string res = sr.ReadToEnd(); Console.WriteLine(res); }The following is the complete code −Example Live Demousing System.IO; using System; public class Demo { public static void Main() { using (StreamWriter sw = new StreamWriter("new.txt")) { sw.WriteLine("One"); sw.WriteLine("Two"); } using (StreamReader sr = new StreamReader("new.txt")) { string res = sr.ReadToEnd(); ... Read More
![karthikeya Boyini](https://www.tutorialspoint.com/assets/profiles/13518/profile/60_31598-1537784993.jpg)
430 Views
To read text files, use StreamReader class in C#.Add the name of the file you want to read −StreamReader sr = new StreamReader("hello.txt");Use the ReadLine() method and get the content of the file in a string −using (StreamReader sr = new StreamReader("hello.txt")) { str = sr.ReadLine(); } Console.WriteLine(str);Let us see the following code −Example Live Demousing System.IO; using System; public class Program { public static void Main() { string str; using (StreamWriter sw = new StreamWriter("hello.txt")) { sw.WriteLine("Hello"); sw.WriteLine("World"); } ... Read More
![Samual Sam](https://www.tutorialspoint.com/assets/profiles/13514/profile/60_83486-1512649303.jpg)
383 Views
The orderby is used in C# to sort elements in the collection based on specified fields in a particular order. The order can be ascending or descending.The following is our list with elements −List myList = new List(); // adding elements myList.Add("iOS by Apple"); myList.Add("Android by Google"); myList.Add("Symbian by Nokia");Now, use Orderby to order the elements in descending order −var myLen = from element in myList orderby element.Length descending select element;The following is the complete code −Example Live Demousing System; using System.Collections.Generic; using System.Linq; class Demo { static void Main() { List myList = new ... Read More