- 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
![Chandu yadav](https://www.tutorialspoint.com/assets/profiles/22330/profile/60_142811-1519038104.jpg)
2K+ Views
The IsDefined method returns true if a given integral value, or its name as a string, is present in a specified enum.The following is our enum −enum Subjects { Maths, Science, English, Economics };The above is initialized by default i.e.Maths = 0, Science = 1, English = 2, Economics = 3Therefore, when we will find 3 using IsDefined(), then it will return True as shown below −Example Live Demousing System; public class Demo { enum Subjects { Maths, Science, English, Economics }; public static void Main() { object ob; ob = 3; Console.WriteLine("{0} = {1}", ob, Enum.IsDefined(typeof(Subjects), ob)); } }Output3 = True
![karthikeya Boyini](https://www.tutorialspoint.com/assets/profiles/13518/profile/60_31598-1537784993.jpg)
4K+ Views
Filter collections using Where clause in C#. A single query expression may have multiple where clauses.Firstly, set a collection −IList employee = new List() { new Employee() { EmpID = 1, EmpName = "Tom", EmpMarks = 90, Rank = 8} , new Employee() { EmpID = 2, EmpName = "Anne", EmpMarks = 60, Rank = 21 } , new Employee() { EmpID = 3, EmpName = "Jack", EmpMarks = 76, Rank = 18 } , new Employee() { EmpID = 4, EmpName = "Amy" , EmpMarks = 67, Rank = 20} , };Now, let’s use multiple ... Read More
![George John](https://www.tutorialspoint.com/assets/profiles/13511/profile/60_58410-1512537824.png)
184 Views
Action delegate does not return a value and can be used with a method that has a void return type.Declare Action Delegate.Action del = Display;Here is our method −public static void Display(int val) { Console.WriteLine(val); }Now call the method with a value.Example Live Demousing System; public class Demo { public static void Main() { Action del = Display; del(2); } public static void Display(int val) { Console.WriteLine(val); } }Output2
![Ankith Reddy](https://www.tutorialspoint.com/assets/profiles/22328/profile/60_142162-1519038074.jpg)
683 Views
Initialize Collection like class objects using collection initializer syntax.Firstly, set values for the Employee object −var emp1 = new Employee() { EID = 001, EmpName = "Tim", EmpDept = "Finance"}; var emp2 = new Employee() { EID = 002, EmpName = "Tom", EmpDept = "HR"};Now add this under a collection.IList empDetails = new List {emp1, emp2 };Let us see the complete code −Example Live Demousing System; using System.Collections.Generic; public class Demo { public static void Main() { var emp1 = new Employee() { EID = 001, EmpName = "Tim", EmpDept = "Finance"}; var emp2 ... Read More
![Samual Sam](https://www.tutorialspoint.com/assets/profiles/13514/profile/60_83486-1512649303.jpg)
319 Views
The Short Time format specifier represents a custom date and time format string.It is defined by the current DateTimeFormatInfo.ShortTimePattern property.For example, the custom format string is −HH:mmExample Live Demousing System; using System.Globalization; class Demo { static void Main() { DateTime date = new DateTime(2018, 5, 4, 10, 12, 10); Console.WriteLine(date.ToString("t", CultureInfo.CreateSpecificCulture("en-us"))); } }Output10:12 AM
![Arjun Thakur](https://www.tutorialspoint.com/assets/profiles/13574/profile/60_74441-1560315595.jpg)
252 Views
The Month standard format specifier represents a custom date and time format string.The format string is defined by the current DateTimeFormatInfo.MonthDayPattern property.The custom format string −MMMM ddExample Live Demousing System; using System.Globalization; class Demo { static void Main() { DateTime date = new DateTime(2018, 6, 11, 9, 15, 0); Console.WriteLine(date.ToString("m", CultureInfo.CreateSpecificCulture("en-us"))); } }OutputJune 11
![karthikeya Boyini](https://www.tutorialspoint.com/assets/profiles/13518/profile/60_31598-1537784993.jpg)
130 Views
Initialize an object of a class with object initialize.Using it, you can assign values to the fields at the time of creating an object.We created Employee object and assigned values using curly bracket at the same time.Employee empDetails = new Employee() { EID = 10, EmpName = "Tim", EmpDept = "Finance" }Now access the values of the Employee class. For example, for name of the employee.empDetails.EmpNameLet us see the complete code −Example Live Demousing System; public class Demo { public static void Main() { Employee empDetails = new Employee() { ... Read More
![Samual Sam](https://www.tutorialspoint.com/assets/profiles/13514/profile/60_83486-1512649303.jpg)
177 Views
The General Date Long Time standard format specifier is a combination of the short date ("d") and long time ("T") patterns, separated by a space.Set the date −DateTime dt = new DateTime(2018, 1, 3, 3, 45, 20);Now, use the ToString() method and DateTimeFormatInfo.dt.ToString("G", DateTimeFormatInfo.InvariantInfo)Example Live Demousing System; using System.Globalization; class Demo { static void Main() { DateTime dt = new DateTime(2018, 1, 3, 3, 45, 20); Console.WriteLine(dt.ToString("G", DateTimeFormatInfo.InvariantInfo)); } }Output01/03/2018 03:45:20
![Chandu yadav](https://www.tutorialspoint.com/assets/profiles/22330/profile/60_142811-1519038104.jpg)
54 Views
A value type representation of the C# Tuple is Value Type Tuple. It was introduced in C# 7.0.Note − Add System.ValueTuple package to run ValueTuple program.Let’s see how to add it −Go to your projectRight click on the project in the Solution ExplorerSelect “Manage NuGet Packages”You will reach the NuGet Package Manager.Now, click the Browse tab and find “ValueTuple”Finally, add System.ValueTuple packageExampleusing System; class Program { static void Main() { var val = (5, 50, 500, 5000); Console.WriteLine("Add System.ValueTuple package to run this program!"); if (val.Item2 == 50) { Console.WriteLine(val); } } }OutputThe following is the output.(5, 50, 500, 5000);
![karthikeya Boyini](https://www.tutorialspoint.com/assets/profiles/13518/profile/60_31598-1537784993.jpg)
60 Views
Firstly, set a string array.string[] num = { "One", "Two", "Three", "Four", "Five"};Use the Linq LongCount method to get the count of elements.num.AsQueryable().LongCount();Here is the complete code −Example Live Demousing System; using System.Collections.Generic; using System.Linq; class Demo { static void Main() { string[] num = { "One", "Two", "Three", "Four", "Five"}; long res = num.AsQueryable().LongCount(); Console.WriteLine("{0} elements", res); } }Output5 elements