- 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 34490 Articles for Programming
![karthikeya Boyini](https://www.tutorialspoint.com/assets/profiles/13518/profile/60_31598-1537784993.jpg)
9K+ Views
Use Hashset to remove duplicate characters.Here is the string −string myStr = "kkllmmnnoo";Now, use HashSet to map the string to char. This will remove the duplicate characters from a string.var unique = new HashSet(myStr);Let us see the complete example −Example Live Demousing System; using System.Linq; using System.Collections.Generic; namespace Demo { class Program { static void Main(string[] args) { string myStr = "kkllmmnnoo"; Console.WriteLine("Initial String: "+myStr); var unique = new HashSet(myStr); Console.Write("New String after removing duplicates: "); foreach (char c in unique) Console.Write(c); } } }OutputInitial String: kkllmmnnoo New String after removing duplicates: klmno
![Chandu yadav](https://www.tutorialspoint.com/assets/profiles/22330/profile/60_142811-1519038104.jpg)
4K+ Views
Convert a string representation of number to an integer, using the int.TryParse and intParse method in C#.If the string cannot be converted, then the int.TryParse method returns false i.e. a Boolean value, whereas int.Parse returns an exception.Let us see an example of int.Parse method −Example Live Demousing System.IO; using System; class Program { static void Main() { int res; string myStr = "120"; res = int.Parse(myStr); Console.WriteLine("String is a numeric representation: "+res); } }OutputString is a numeric representation: 120Let us see an example of int.TryParse method.Example Live Demousing ... Read More
![karthikeya Boyini](https://www.tutorialspoint.com/assets/profiles/13518/profile/60_31598-1537784993.jpg)
5K+ Views
Set two arrays.var val = new [] { 20, 40, 60}; var str = new [] { "ele1", "ele2", "ele3"};Use the zip() method to process the two arrays in parallel.var res = val.Zip(str, (n, w) => new { Number = n, Word = w });The above fetches both the arrays with int and string elements respectively.Now, use foreach to iterate the two arrays −Example Live Demousing System; using System.Collections.Generic; using System.Linq; public class Demo { public static void Main() { var val = new [] { 20, 40, 60}; var str = new ... Read More
![Samual Sam](https://www.tutorialspoint.com/assets/profiles/13514/profile/60_83486-1512649303.jpg)
217 Views
Firstly, set two lists in C#.List OneList list1 = new List (); list1.Add("P"); list1.Add("Q"); list1.Add("R"); list1.Add("S"); list1.Add("T"); list1.Add("U"); list1.Add("V"); list1.Add("W");List TwoList list2 = new List (); list2.Add("T"); list2.Add("U"); list2.Add("V"); list2.Add("W");Now, to get the different values in both the lists, use the Except method. It returns the values in the first list which is not present in the second list.Example Live Demousing System; using System.Collections.Generic; using System.Linq; public class Demo { public static void Main() { List list1 = new List (); list1.Add("P"); list1.Add("Q"); ... Read More
![Ankith Reddy](https://www.tutorialspoint.com/assets/profiles/22328/profile/60_142162-1519038074.jpg)
682 Views
The Func generic type store anonymous methods and is a parameterized type.In the below example, we have 4 func type instance −The first type receives int and returns stringFunc one = (p) => string.Format("{0}", p);The second type receives bool & long and returns stringFunc two = (q, p) =>string.Format("{0} and {1}", q, p);The third type receives bool & int and returns stringFunc three = (q, p) => string.Format("{0} and {1}", q, p);The fourth type receives decimal and returns stringFunc four = (p) =>string.Format("{0}", p);Let us see how to display them −Example Live Demousing System; using System.IO; namespace Demo { ... Read More
![George John](https://www.tutorialspoint.com/assets/profiles/13511/profile/60_58410-1512537824.png)
240 Views
EnumerateFile() method is used in C# to get all the files. Use AllDirectories property to recurse through directories −Directory.EnumerateFiles(@"D:\NEW", "*.*", SearchOption.AllDirectories)To get the list of files in a directory, use the SearchOptions.AllDirectories in C# as shown above.Let us see how −Exampleusing System; using System.IO; namespace Demo { class Program { static void Main(string[] args) { foreach (string allFiles is Directory.EnumerateFiles(@"D:\NEW","*.*",SearchOption.AllDirectories)) { Console.WriteLine(allFiles); } } } }OutputThe following is the output −D:\NEW\my.txt D:\NEW\amit.html D:\NEW\tutorials\java\a.java
![Chandu yadav](https://www.tutorialspoint.com/assets/profiles/22330/profile/60_142811-1519038104.jpg)
169 Views
To get all the disk drives on a system, use the GetLogicalDrives() method in C# −Environment.GetLogicalDrives()Use it with Join method to get the comma-separated list of logical drives −string.Join(",", Environment.GetLogicalDrives())Example Live Demousing System; using System.IO; namespace Demo { class Program { static void Main(string[] args) { Console.WriteLine(string.Join(",", Environment.GetLogicalDrives())); } } }Output/,/etc/resolv.conf,/etc/hostname,/etc/hosts,/run/secrets,/home/cg/root
![Arjun Thakur](https://www.tutorialspoint.com/assets/profiles/13574/profile/60_74441-1560315595.jpg)
2K+ Views
The Enviornment.NewLine in C# is used to add newline.To set a new line in between words −str = "This is demo text!" + Environment.NewLine + "This is demo text on next line!";The following is the code −Example Live Demousing System; using System.IO; namespace Demo { class Program { static void Main(string[] args) { string str = "This is demo text!" + Environment.NewLine + "This is demo text on next line!"; Console.Write(str); } } }OutputThis is demo text! This is demo text on next line!
![Chandu yadav](https://www.tutorialspoint.com/assets/profiles/22330/profile/60_142811-1519038104.jpg)
560 Views
Set the path name in a string −string myPath = "D:ew\quiz.txt";Now, use the GetFileName() method to get the name of the file −Path.GetFileName(myPath)The following is the complete code −Example Live Demousing System; using System.IO; namespace Demo { class Program { static void Main(string[] args) { string myPath = "D:ew\quiz.txt"; // get extension Console.WriteLine("Extension: "+Path.GetExtension(myPath)); // get path Console.WriteLine("File Path: "+Path.GetFileName(myPath)); } } }OutputExtension: .txt File Path: D:ew\quiz.txt