- 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
![karthikeya Boyini](https://www.tutorialspoint.com/assets/profiles/13518/profile/60_31598-1537784993.jpg)
6K+ Views
Firstly, set the array with duplicate elements.int[] arr = { 24, 10, 56, 32, 10, 43, 88, 32 };Now declare a Dictionary and loop through the array to get the repeated elements.var d = new Dictionary < int, int > (); foreach(var res in arr) { if (d.ContainsKey(res)) d[res]++; else d[res] = 1; }Example Live Demousing System; using System.Collections.Generic; namespace Demo { public class Program { public static void Main(string[] args) { int[] arr = { ... Read More
![George John](https://www.tutorialspoint.com/assets/profiles/13511/profile/60_58410-1512537824.png)
10K+ Views
Firstly, set the 12 hr format date.DateTime d = DateTime.Parse("05:00 PM");Now let us convert it into 24-hr format.d.ToString("HH:mm"));The following is the code to covert time from 12 hour to 24 hour format −Example Live Demousing System; namespace Demo { public class Program { public static void Main(string[] args) { DateTime d = DateTime.Parse("05:00 PM"); Console.WriteLine(d.ToString("HH:mm")); } } }Output17:00
![Samual Sam](https://www.tutorialspoint.com/assets/profiles/13514/profile/60_83486-1512649303.jpg)
1K+ Views
Take two arrays:int[] arr2 = new int[5]; int[] arr3 = new int[5];Now, if the array element gets the remainder 0 on dividing by 2, it is even. Get those elements and add in another array. This loops through the length of the array:if (arr1[i] % 2 == 0) { arr2[j] = arr1[i]; }In the else condition, you will get the odd elements. Add them to a separate array and display them individually as shown in the below example:Example Live Demousing System; namespace Demo { public class Program { public static void Main(string[] args) { ... Read More
![Chandu yadav](https://www.tutorialspoint.com/assets/profiles/22330/profile/60_142811-1519038104.jpg)
3K+ Views
Let’s say you need to get the value of 10 dollars in INR.Firstly, set the variables: double usd, inr, val;Now set the dollars and convert it to INR.// how many dpllars usd = 10; // current value of US$ val = 69; inr = usd * val;Let us see the complete code −Example Live Demousing System; namespace Demo { public class Program { public static void Main(string[] args) { Double usd, inr, val; // how many dpllars usd = 10; // current value of US$ val = 69; inr = usd * val; Console.WriteLine("{0} Dollar = {1} INR", usd, inr); } } }Output10 Dollar = 690 INR
![karthikeya Boyini](https://www.tutorialspoint.com/assets/profiles/13518/profile/60_31598-1537784993.jpg)
383 Views
We have set an array and a dictionary to get the distinct elements.int[] arr = { 88, 23, 56, 96, 43 }; var d = new Dictionary < int, int > ();Dictionary collection allows us to get the key and value of a list.The following is the code to display distinct elements of a given integer array −Example Live Demousing System; using System.Collections.Generic; namespace Demo { public class Program { public static void Main(string[] args) { int[] arr = { 88, ... Read More
![Arjun Thakur](https://www.tutorialspoint.com/assets/profiles/13574/profile/60_74441-1560315595.jpg)
758 Views
The following is our array −int[] arr = new int[] { 7, 4, 6, 2 };Let’s say the given intger that should be equal to sum of two other integers is −int res = 8;To get the sum and find the equality.for (int i = 0; i < arr.Length; i++) { for (int j = 0; j < arr.Length; j++) { if (i != j) { int sum = arr[i] + arr[j]; if (sum == res) { Console.WriteLine(arr[i]); ... Read More
![Ankith Reddy](https://www.tutorialspoint.com/assets/profiles/22328/profile/60_142162-1519038074.jpg)
2K+ Views
Declare a list.List < string > l = new List < string > ();Now, add elements to the list.// elements l.Add("Accessories"); l.Add("Footwear"); l.Add("Watches");Now convert it into a string.string str = string.Join(" ", l.ToArray());Let us see the final code to convert a list to string in C# −Exampleusing System; using System.Collections.Generic; class Demo { static void Main() { List < string > l = new List < string > (); // elements l.Add("Accessories"); l.Add("Footwear"); l.Add("Watches"); string str = string.Join(" ", l.ToArray()); Console.WriteLine(str); } }
![Samual Sam](https://www.tutorialspoint.com/assets/profiles/13514/profile/60_83486-1512649303.jpg)
668 Views
To print duplicates from a list of integers, use the ContainsKey.Below, we have first set the integers.int[] arr = { 3, 6, 3, 8, 9, 2, 2 };Then Dictionary collection is used to get the count of duplicate integers.Let us see the code to get duplicate integers.Example Live Demousing System; using System.Collections.Generic; namespace Demo { public class Program { public static void Main(string[] args) { int[] arr = { 3, 6, ... Read More
![karthikeya Boyini](https://www.tutorialspoint.com/assets/profiles/13518/profile/60_31598-1537784993.jpg)
410 Views
To format string literals in C#, use the String.Format method.In the following example, 0 is the index of the object whose string value gets inserted at that particular position −using System; namespace Demo { class Test { static void Main(string[] args) { decimal A = 15.2 m; string res = String.Format("Temperature = {0}°C.", A); Console.WriteLine(res); } } }In the following example, let us format string for double type.Example Live Demousing System; class Demo { public static void Main(String[] args) { ... Read More
![George John](https://www.tutorialspoint.com/assets/profiles/13511/profile/60_58410-1512537824.png)
1K+ Views
To format output in C#, let us see examples to format date and double type.Set formatted output for Double type.Example Live Demousing System; class Demo { public static void Main(String[] args) { Console.WriteLine("Three decimal places..."); Console.WriteLine(String.Format("{0:0.000}", 987.383)); Console.WriteLine(String.Format("{0:0.000}", 987.38)); Console.WriteLine(String.Format("{0:0.000}", 987.7899)); Console.WriteLine("Thousands Separator..."); Console.WriteLine(String.Format("{0:0, 0.0}", 54567.46)); Console.WriteLine(String.Format("{0:0, 0}", 54567.46)); } }OutputThree decimal places... 987.383 987.380 987.790 Thousands Separator... 54, 567.5 54, 567Set formatted output for DateTimeExample Live Demousing System; static class Demo { static void Main() ... Read More