 
  Data Structure Data Structure
 Networking Networking
 RDBMS RDBMS
 Operating System Operating System
 Java Java
 MS Excel MS Excel
 iOS iOS
 HTML HTML
 CSS CSS
 Android Android
 Python Python
 C Programming C Programming
 C++ C++
 C# C#
 MongoDB MongoDB
 MySQL MySQL
 Javascript Javascript
 PHP PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Get first three letters from every string in C#
The following are our strings in a list −
List<object> list = new List<object> { "keyboard", "mouse", "joystick", "monitor" }; To use the first 3 letters, use substring method and use it under the Linq Select method.
IEnumerable<string> res = list.AsQueryable() .Cast<string>() .Select(str => str.Substring(0, 3));
Example
using System; using System.Linq; using System.Collections.Generic; class Demo {    static void Main() {       List<object> list = new List<object> { "keyboard", "mouse", "joystick", "monitor" };       // getting first 3 letters from every string       IEnumerable<string> res = list.AsQueryable() .Cast<string>() .Select(str =>       str.Substring(0,3));       foreach (string str in res) {          Console.WriteLine(str);       }    } }  Output
key mou joy mon
Advertisements
 