- 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
George John has Published 1167 Articles
George John
249 Views
Create more than one list −// two lists var list1 = new List{3, 4}; var list2 = new List{1, 2, 3};Now, use the Intersect() method to get the common values −var res = list1.Intersect(list2);The following is the complete code −Example Live Demousing System.Collections.Generic; using System.Linq; using System; public class Demo ... Read More
George John
276 Views
Use the Truncate method in C# to remove all the numbers after decimal places.Let’s say the following is our number −20.35MTo remove the numbers after decimal places, use Truncate() −decimal.Truncate(20.35M)Let us see the comple code −Exampleusing System; using System.Linq; class Demo { static void Main() { ... Read More
George John
505 Views
To open a hidden file, first make it visible. You can do this by removing the hidden attribute set on it −FileInfo file= new FileInfo(Environment.CurrentDirectory + @"\myFile.txt"); file.Attributes &= ~FileAttributes.Hidden;Now treat it as a normal text file and open it. Read the content −using (StreamReader sr = new StreamReader("myFile.txt")) { ... Read More
George John
820 Views
To create a new file in C#, use the FileStream object.The following is the syntax −FileStream = new FileStream( , , , );Let us see an example for a file “test.dat”, which is created/ opened using File object −FileStream F = new FileStream("test.dat", FileMode.OpenOrCreate, FileAccess.ReadWrite);The following is an example ... Read More
George John
538 Views
To list all the substrings, use the Substring method and loop through the length of the string.Let’s say our string is −string myStr = "pqrz";Use nested loop and get the substring in a new string −for (int i = 1; i < myStr.Length; i++) { for (int start = 0; start
George John
2K+ Views
Firstly, set a list −List list = new List(); list.Add(456); list.Add(321); list.Add(123); list.Add(877); list.Add(588); list.Add(459);Now, to add an item at index 5, let say; for that, use the Insert() method −list.Insert(5, 999);Let us see the complete example −Exampleusing System; using System.Collections.Generic; namespace Demo { public class Program { ... Read More
George John
957 Views
Use the new keyword to instantiate a delegate. When creating a delegate, the argument passed to the new expression is written similar to a method call, but without the arguments to the method.For example −public delegate void printString(string s); printString ps1 = new printString(WriteToScreen);You can also instantiate a delegate using ... Read More
George John
76 Views
Following are the ways with the help of which current MySQL transaction can be ended implicitly −By Running DDL statementThe current MySQL transaction will end implicitly and changes will be committed by running any of the DDL statement such as CREATE or DROP databases, Create, ALTER or DROP tables or ... Read More
George John
245 Views
Let’s say our string is −string str ="9999";Now, use the Int32.Parse() to convert the string into integer −int n = Int32.Parse(str);Now display the integer value as shown in the following code −Exampleusing System; class Demo { static void Main() { string str ="9999"; ... Read More
George John
89 Views
Use the GetDirectories in C# to get a list of sub-folder that appears first −Directory.GetDirectoriesNow loop through those directories and repeat the process for the sub folder.string path = @"d:/New/Myfile"; string[] myDir = Directory.GetDirectories(path, "xml", SearchOption.AllDirectories); Console.WriteLine(myDir.Length.ToString()); foreach (string res in myDir) Console.WriteLine(res);Read More