- 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
![Ankith Reddy](https://www.tutorialspoint.com/assets/profiles/22328/profile/60_142162-1519038074.jpg)
13K+ Views
Use DateTime. DayOfWeek property to display the current day of week.DayOfWeek wk = DateTime.Today.DayOfWeek;Now, displaying “wk” would give you the current day of the week.Let us see the complete code to get the current day of week.Example Live Demousing System; using System.Linq; public class Demo { public static void Main() { DayOfWeek wk = DateTime.Today.DayOfWeek; Console.WriteLine(wk); } }OutputWednesday
![karthikeya Boyini](https://www.tutorialspoint.com/assets/profiles/13518/profile/60_31598-1537784993.jpg)
264 Views
Use All() Method to check whether the elements of a sequence satisfy a condition or not. Even if one of the element do not satisfy the set condition, the All() method returns False.To set conditions, use Lambda Expressions. Below shows a condition to check whether all the elements are greater than 20 or not.myArr.AsQueryable().All(val => val > 20);Let us see an example.Example Live Demousing System; using System.Linq; class Demo { static void Main() { int[] myArr = {7, 15, 22, 30, 40}; // checking if all the array elements are greater than 20 bool res = myArr.AsQueryable().All(val => val > 20); Console.WriteLine(res); } }OutputFalse
![Arjun Thakur](https://www.tutorialspoint.com/assets/profiles/13574/profile/60_74441-1560315595.jpg)
343 Views
Use the AsEnumerable() method to cast a type to its IEnumerable equivalent. It is an extension method.For our example, we have set an array.int[] myArr = new int[10]; myArr[0] = 1; myArr[1] = 2; myArr[2] = 3; myArr[3] = 4; myArr[4] = 5;Now, we have used the AsEnumerable() method to cast.myArr.AsEnumerable();Example Live Demousing System; using System.Linq; class Demo { static void Main() { int[] myArr = new int[10]; myArr[0] = 1; myArr[1] = 2; myArr[2] = 3; myArr[3] = 4; myArr[4] = 5; myArr[5] = 6; myArr[6] = 7; myArr[7] = 8; myArr[8] = 9; myArr[9] = 10; // AsEnumerable var a = myArr.AsEnumerable(); // Displaying foreach (var item in a) { Console.WriteLine(item); } } }Output1 2 3 4 5 6 7 8 9 10
![Samual Sam](https://www.tutorialspoint.com/assets/profiles/13514/profile/60_83486-1512649303.jpg)
6K+ Views
Let’s say the following are two DateTime objects for our dates.DateTime date1 = new DateTime(2018, 8, 11, 08, 15, 20); DateTime date2 = new DateTime(2018, 8, 11, 11, 14, 25);Find the difference between both these dates using TimeSpan.TimeSpan ts = date2 - date1;Now to get the Milliseconds, use the following property −ts.TotalMillisecondsLet us see the complete code.Example Live Demousing System; using System.Linq; public class Demo { public static void Main() { DateTime date1 = new DateTime(2018, 8, 11, 08, 15, 20); DateTime date2 = new DateTime(2018, 8, 11, 11, 14, 25); TimeSpan ts = date2 - date1; Console.WriteLine("No. of Seconds (Difference) = {0}", ts.TotalMilliseconds); } }OutputNo. of Seconds (Difference) = 10745000
![Ankith Reddy](https://www.tutorialspoint.com/assets/profiles/22328/profile/60_142162-1519038074.jpg)
173 Views
The WindowsLeft property gets or sets the leftmost position of the console window area relative to the screen buffer.Declare an integer variable to get the leftmost position.int left;Now, use the Console.WindowLeft property.left = Console.WindowLeftLet us see the complete example.Example Live Demousing System; class Demo { static void Main() { int left; left = Console.WindowLeft; Console.WriteLine("Left position of the Console window = "+left); } }OutputNote: The output may vary accordingly based on the position of the Console WindowLeft position of the Console window = 0
![George John](https://www.tutorialspoint.com/assets/profiles/13511/profile/60_58410-1512537824.png)
17K+ Views
Firstly, set the two dates.DateTime date1 = new DateTime(2018, 7, 15, 08, 15, 20); DateTime date2 = new DateTime(2018, 8, 17, 11, 14, 25);Now, calculate the difference between two dates.TimeSpan ts = date2 - date1;To calculate minutes.ts.TotalMinutesLet us see the complete code.Example Live Demousing System; using System.Linq; public class Demo { public static void Main() { DateTime date1 = new DateTime(2018, 7, 15, 08, 15, 20); DateTime date2 = new DateTime(2018, 8, 17, 11, 14, 25); TimeSpan ts = date2 - date1; Console.WriteLine("No. of Minutes (Difference) = {0}", ts.TotalMinutes); } }OutputNo. of Minutes (Difference) = 47699.0833333333
![karthikeya Boyini](https://www.tutorialspoint.com/assets/profiles/13518/profile/60_31598-1537784993.jpg)
5K+ Views
Set two dates.DateTime date1 = new DateTime(2018, 7, 15, 08, 15, 20); DateTime date2 = new DateTime(2018, 7, 15, 11, 14, 25);Now calculate the difference between two dates.TimeSpan ts = date2 - date1;Move further and calculate the difference in seconds.ts.TotalSecondsLet us see the complete code.Example Live Demousing System; using System.Linq; public class Demo { public static void Main() { DateTime date1 = new DateTime(2018, 7, 15, 08, 15, 20); DateTime date2 = new DateTime(2018, 7, 15, 11, 14, 25); TimeSpan ts = date2 - date1; Console.WriteLine("No. of Seconds (Difference) = {0}", ts.TotalSeconds); } }OutputNo. of Seconds (Difference) = 10745
![Samual Sam](https://www.tutorialspoint.com/assets/profiles/13514/profile/60_83486-1512649303.jpg)
154 Views
The WindowHeight property gets or sets the height of the console window.Declare a variable.int height;Now, get the height of the current window.height = Console.WindowHeight;The following is the complete example −Example Live Demousing System; using System.Numerics; using System.Globalization; class Demo { static void Main() { int height; height = Console.WindowHeight; Console.WriteLine("Current window height = "+height); } }OutputCurrent window height = 0
![Chandu yadav](https://www.tutorialspoint.com/assets/profiles/22330/profile/60_142811-1519038104.jpg)
210 Views
Set a LinkedList and add elements.string [] students = {"Beth", "Jennifer", "Amy", "Vera"}; LinkedList list = new LinkedList(students);Firstly, add a new node at the end.var newNode = list.AddLast("Emma");Now, use the AddAfter() method to add a node after the given node.list.AddAfter(newNode, "Matt");The following is the complete code.Example Live Demousing System; using System.Collections.Generic; class Demo { static void Main() { string [] students = {"Beth", "Jennifer", "Amy", "Vera"}; LinkedList list = new LinkedList(students); foreach (var stu in list) { Console.WriteLine(stu); } // ... Read More
![Samual Sam](https://www.tutorialspoint.com/assets/profiles/13514/profile/60_83486-1512649303.jpg)
9K+ Views
Set two dates.DateTime date1 = new DateTime(2018, 7, 15, 08, 15, 20); DateTime date2 = new DateTime(2018, 8, 17, 11, 14, 25);Now, get the difference between two dates.TimeSpan ts = date2 - date1;Get the result i.e. the difference in hours.ts.TotalHoursLet us see the complete code.Example Live Demousing System; using System.Linq; public class Demo { public static void Main() { DateTime date1 = new DateTime(2018, 7, 15, 08, 15, 20); DateTime date2 = new DateTime(2018, 8, 17, 11, 14, 25); TimeSpan ts = date2 - date1; Console.WriteLine("No. of Hours (Difference) = {0}", ts.TotalHours); } }OutputNo. of Hours (Difference) = 794.984722222222