- 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 34488 Articles for Programming
![Ankith Reddy](https://www.tutorialspoint.com/assets/profiles/22328/profile/60_142162-1519038074.jpg)
55 Views
The ToEven property is used with the MidpointRounding Enumeration to round a number to the nearest even number.Declare and initialize a decimal number −decimal val = 70.45M;To rounde a number to the nearest even number −decimal.Round(val, 0, MidpointRounding.ToEven)Here is the complete code −Example Live Demousing System; using System.Linq; class Demo { static void Main() { decimal val = 70.45M; Console.WriteLine(decimal.Round(val, 0, MidpointRounding.ToEven)); } }Output70
![George John](https://www.tutorialspoint.com/assets/profiles/13511/profile/60_58410-1512537824.png)
277 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() { decimal dc = 20.35M; Console.WriteLine(dc.Truncate(val)); } }
![Chandu yadav](https://www.tutorialspoint.com/assets/profiles/22330/profile/60_142811-1519038104.jpg)
70 Views
Let’s say we need to find the following file −E:ew.txtTo check the existence of the above file, use the Exists() method −if (File.Exists(@"E:ew.txt")) { Console.WriteLine("File exists..."); }Here is the complete code to check the existence of a file −Example Live Demousing System; using System.IO; public class Demo { public static void Main() { if (File.Exists(@"E:ew.txt")) { Console.WriteLine("File exists..."); } else { Console.WriteLine("File does not exist in the E directory!"); } } }OutputFile does not exist in the E directory!
![varma](https://www.tutorialspoint.com/assets/profiles/13568/profile/60_26300-1512638592.jpg)
1K+ Views
The garbage collector (GC) manages the allocation and release of memory. The garbage collector serves as an automatic memory manager. You do not need to know how to allocate and release memory or manage the lifetime of the objects that use that memory. An allocation is made any time you declare an object with a “new” keyword or a value type is boxed. Allocations are typically very fast. When there is not enough memory to allocate an object, the GC must collect and dispose of garbage memory to make memory available for new allocations. This process is known as ... Read More
![karthikeya Boyini](https://www.tutorialspoint.com/assets/profiles/13518/profile/60_31598-1537784993.jpg)
960 Views
A nested class is a class declared in another enclosing class and it has inner as well as outer class. It is a member of its enclosing class and the members of an enclosing class have no access to members of a nested classLet us see an example code snippet of nested classes in C#.Here, class Two is a local inner class −Exampleclass One { public int num1; public class Two { public int num2; } } class Demo { static void Main() { One x = new One(); ... Read More
![Samual Sam](https://www.tutorialspoint.com/assets/profiles/13514/profile/60_83486-1512649303.jpg)
550 Views
InheritanceWith Inheritance, you can designate that the new class should inherit the members of an existing class. This existing class is called the baseclass, and the new class is referred to as the derived class. Inheritance implements the IS-A relationship. For example, mammal IS A animal, dog IS-A mammal hence dog IS-A animal as well, and so on.For example, A base class Shape has a derived classes like Circle, Square, Rectangle, etc.CompositionUnder Composition, if the parent object is deleted, then the child object also loses its status. Composition is a special type of Aggregation and gives a part-of relationship.For example, ... Read More
![karthikeya Boyini](https://www.tutorialspoint.com/assets/profiles/13518/profile/60_31598-1537784993.jpg)
556 Views
Set the string as empty using the string.Empty in C# −string myStr = string.Empty;To check whether it is a string or not, use the IsNullOrEmpty() method −if (string.IsNullOrEmpty(myStr)) { Console.WriteLine("String is empty or null!"); }The following is an example −Example Live Demousing System; namespace Demo { public class Program { public static void Main(string[] args) { string myStr = string.Empty; if (string.IsNullOrEmpty(myStr)) { Console.WriteLine("String is empty or null!"); } else { Console.WriteLine("String isn't empty or null!"); } } } }OutputString is empty or null!
![Samual Sam](https://www.tutorialspoint.com/assets/profiles/13514/profile/60_83486-1512649303.jpg)
1K+ Views
To make a C# program sleep for x milliseconds, use the Thread.Sleep() method.To set it for 1000 milliseconds −Thread.Sleep(1000);The following is the code showing how to set a counter for the thread and set it to sleep for 1000 milliseconds on every iteration of for loop −Example Live Demousing System; using System.Threading; namespace MultithreadingApplication { public class ThreadCreationProgram { public static void CallToChildThread() { try { Console.WriteLine("Child thread starts"); for (int counter = 0; counter
![karthikeya Boyini](https://www.tutorialspoint.com/assets/profiles/13518/profile/60_31598-1537784993.jpg)
58 Views
Declaring an array does not initialize the array in the memory. When the array variable is initialized, you can assign values to the array.The following is a declaration and it will not create an array −int[] id;The following create an array of integers. The array is a reference type, so you need to use the new keyword to create an instance of the array −Int[] id = new int[5] {};Let us see an example −Example Live Demousing System; namespace ArrayApplication { public class MyArray { public static void Main(string[] args) { int ... Read More
![Samual Sam](https://www.tutorialspoint.com/assets/profiles/13514/profile/60_83486-1512649303.jpg)
309 Views
Precision states the difference between float and double data type. Float is a single precision (32 bit) floating point data type. Double is a double precision (64 bit) floating point data type. Range of a float type − -3.4 x 1038 to + 3.4 x 1038 Range of a double type is − (+/-)5.0 x 10-324 to (+/-)1.7 x 10308 Default value of a float type − 0.0F Default value of a double type − 0.0D