- 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 34489 Articles for Programming
705 Views
Use SelectMany method to collapse elements into a single collection like an error.An example would be to convert string to character array. The following is our string array.string[] str = { "Mobile", "Laptop", "Tablet" };Now, convert to character array.str.SelectMany(item => item.ToCharArray());Example Live Demousing System; using System.Linq; using System.Collections.Generic; public class Demo { public static void Main() { string[] str = { "Mobile", "Laptop", "Tablet" }; var res = str.SelectMany(item => item.ToCharArray()); Console.WriteLine("String converted to character array: "); foreach (char letter in res) { Console.Write(letter); } } }OutputString converted to character array: MobileLaptopTablet
2K+ Views
Use the Select method to modify the elements in an array.The following is our string array.string[] stationery = { "diary", "board", "pencil", "whiteboard" };The Select method also specifies Lambda Expressions as shown below −Example Live Demousing System; using System.Linq; using System.Collections.Generic; public class Demo { public static void Main() { string[] stationery = { "diary", "board", "pencil", "whiteboard" }; var res = stationery.AsQueryable().Select((item, index) => new { result = item.Substring(0, index + 4) }); foreach (var str in res) { Console.WriteLine("{0}", str); } } }Output{ result = diar } { result = board } { result = pencil } { result = whitebo }
426 Views
Use Select method and Lambda Expression to calculate the cube of elements.The following is our list.List list = new List { 2, 4, 5, 7 };Now, use the Select() method and calculate the cube.list.AsQueryable().Select(c => c * c * c);The following is the entire example.Example Live Demousing System; using System.Linq; using System.Collections.Generic; public class Demo { public static void Main() { List list = new List { 2, 4, 5, 7 }; Console.WriteLine("Elements..."); // initial list javascript:void(0) foreach (int n in list) Console.WriteLine(n); ... Read More
115 Views
The WindowsTop property is used to gets or set the top position of the console window area relative to the screen buffer.Declare an integer variable to get the top position.int top;Now, use the Console.WindowTop property.top = Console.WindowTop;Let us see the complete example.Example Live Demousing System; class Demo { static void Main() { int top; top = Console.WindowTop; Console.WriteLine("Top position of the Console window = "+top); } }OutputTop position of the Console window = 0
122 Views
Use the BufferWidth gets or sets the width of the buffer area.Use the property like this −Console.BufferWidthLet us see the complete example.Example Live Demousing System; class Demo { static void Main() { Console.WriteLine("Buffer width (columns) = "+Console.BufferWidth); } }OutputBuffer width (columns) = 0
747 Views
Reverse the elements in an array, using the Reverse method.Here is our character array.char[] ch = { 't', 'i', 'm', 'e' };Now use the Reverse() method with AsQueryable() method to get the reverse.ch.AsQueryable().Reverse();Let us see the complete code.Example Live Demousing System; using System.Linq; using System.Collections.Generic; public class Demo { public static void Main() { char[] ch = { 't', 'i', 'm', 'e' }; Console.Write("String = "); foreach(char arr in ch) { Console.Write(arr); } IQueryable res = ch.AsQueryable().Reverse(); Console.Write("Reversed String = "); foreach (char c in res) { Console.Write(c); } } }OutputString = time Reversed String = emit
158 Views
The Full Date Long Time standard format specifier’s custom date and time format string is defined by the current DateTimeFormatInfo.FullDateTimePattern property.The custom format string is −dddd, dd MMMM yyyy HH:mm:ssExample Live Demousing System; using System.Globalization; class Demo { static void Main() { DateTime myDate = new DateTime(2018, 8, 13, 9, 15, 0); Console.WriteLine(myDate.ToString("F", CultureInfo.CreateSpecificCulture("en-US"))); } }OutputMonday, August 13, 2018 9:15:00 AM
310 Views
UShort represents a 16-bit unsigned integer.To implicitly convert of a 16-bit unsigned integer to a decimal, firstly set a ushort value.ushort val = 193;To convert ushort to decimal, assign the value.decimal dec; dec = val;Let us see an example.Exampleusing System; public class Demo { public static void Main() { ushort val = 2567; decimal dec; Console.WriteLine("Implicit conversion from 16-bit unsigned integer to Decimal"); dec = val; Console.WriteLine("Decimal = "+dec); } }
308 Views
Use Orderby descending in C# to sort elements in descending order.The following is our list −IList emp = new List() { new Employee() { EmployeeRank = 3, EmpName = "Tom", EmpMarks = 90 } , new Employee() { EmployeeRank = 4, EmpName = "Katie", EmpMarks = 95 } };Now to sort the list according to Student name, use Orderby. The default is ascending, therefore for descending order, use descending.var res = from str in emp orderby str.EmpName descending select str;Here is the complete code.Example Live Demousing System; using System.Linq; using System.Collections.Generic; public class Demo { public static void Main() { ... Read More
920 Views
To represent Int32 as a Octal string in C#, use the ToString() method and set the base as the ToString() method’s second parameter i.e. 8 for Octal.Int32 represents a 32-bit signed integer.Firstly, set an Int32 variable.int val = 99;Now, convert it to octal string by including 8 as the second parameter.Convert.ToString(val, 8)Example Live Demousing System; class Demo { static void Main() { int val = 99; Console.WriteLine("Integer: "+val); Console.Write("Octal String: "+Convert.ToString(val, 8)); } }OutputInteger: 99 Octal String: 143