- 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 35164 Articles for Programming
14K+ Views
Convert a string representation of number to an integer, using the int.Parse method in C#. If the string cannot be converted, then the int.Parse method returns an exceptionLet’s say you have a string representation of a number.string myStr = "200";Now to convert it to an integer, use the int.Parse(). It will get converted.int.Parse(myStr);Example Live Demousing System.IO; using System; class Program { static void Main() { int res; string myStr = "200"; res = int.Parse(myStr); Console.WriteLine("String is a numeric representation: "+res); } }OutputString is a numeric representation: 200
1K+ 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
3K+ 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
159 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
611 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
279 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
228 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
116 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
155 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
43 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);