0

what is the c# code concatenate two different datatype column in single column with bind dropdownlist ?

2
Contributors
1
Reply
2
Views
5 Years
Discussion Span
Last Post by thines01
0

That will really depend on the data types.

So, look at this example where I have a list of strings and a list of integers that I want to connect.
I can simply do a foreach (or something else) to match them one-to-one.
It really depends on how the data fits together, the type of data and the data type of the result.

using System.Collections.Generic;
using System.Linq;

namespace DW_409612_CS_CON
{
   class Program
   {
      static void Main(string[] args)
      {
         List<string> lst_str = new List<string> { "a", "b", "c" };
         List<int> lst_int = new List<int> { 17, 52, 64 };

         //List<string> lst_str2 =
         (
            from str in lst_str
            let i_strOffset = lst_str.IndexOf(str)
            from i in lst_int
            let i_intOffset = lst_int.IndexOf(i)
            where i_strOffset.Equals(i_intOffset)
            select (str + '-' + i.ToString())
         ).ToList().ForEach(s => System.Diagnostics.Debug.WriteLine(s));
      }
   }
}

output (in Debug Window):

a-17
b-52
c-64

Edited by thines01: added code

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.