Skip to main content

Posts

Showing posts from August 11, 2021

Beginners Coding Challenge : C# Program to convert the list of string to CSV with quotes

Beginners Level: C# Program to convert the list of string to CSV with quotes  There may be the situation where we need to build any dynamic SQL queries to fetch the data programmatically, Example: SELECT * FROM ORDERS WHERE DELIVERY_LOCATION IN ('Sydney', 'Singapore', 'Tokyo', 'Jakarta'); For this we need to have  // Program to convert the list of string to CSV with quotes static void Main( string [] args) {   List < string > LstCities = new List < string >();   LstCities .Add( " Sydney "); LstCities .Add( " Singapore "); LstCities .Add( " Tokyo "); LstCities .Add( " Jakarta ");     string InClause = string .Format( "'{0}'" , string .Join( "','" , LstCities )); Console .WriteLine( InClause ); Console .ReadLine(); } This will print 4 city names in the following format  ' Sydney ', ' Singapore ', ' Tokyo ', ' Jakarta '