- 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
Stopwatch class in C#
Stopwatch is a class in C# to measure the elapsed time. Use it to calculate the time a function took to execute. It is found under System.Diagnostics.
To get the elapsed time, firstly begin the Stopwatch −
var sw = Stopwatch.StartNew();
For elapsed ticks −
long ticks = sw.ElapsedTicks;
Let us see an example −
Example
using System; using System.Linq; using System.Diagnostics; public class Demo { public static void Main() { var sw = Stopwatch.StartNew(); long ticks = sw.ElapsedTicks; Console.WriteLine(ticks); } }
Output
582
Advertisements