-1

Model

 public partial class IndustryLandingHeader :EntityModel
 {
 [TextField]
    public virtual string Headline { get; set; }
    [TextField]
    public virtual string Type { get; set; }
    [KeywordField]
    public virtual KeyWordMetaSchema ParentIndustry { get; set; }
    [KeywordField]
    public virtual List<KeyWordMetaSchema> SubIndustries { get; set; }
    [TextField]
    public virtual string LabelForSubIndustry { get; set; }
    [KeywordTitleField]
    public virtual List<KeyWordMetaSchema> AdditionalKeyword { get; set; }
 }

need to combine SUBINDUSTRIES and ADDITIONALKEYWORD variable alone as single variable Here I have two different variable name needs to be combined to single variable .How to do that?

Jeevitha
  • 121
  • 8

4 Answers4

1

You can use the LINQ Concat and ToList methods

var allProducts = productCollection1.Concat(productCollection2)
                                .Concat(productCollection3)
                                .ToList();
0

You can create a new collection and add there:

...
var combineList = new List<KeyWordMetaSchema>();

combineList.AddRange(industryLandingHeades.SubIndustries);
combineList.AddRange(industryLandingHeades.AdditionalKeyword);
Igor N.
  • 41
  • 1
  • 8
  • If you are going to do it this way (which I am not suggesting, but if you are) you may as well pass the expected size (i.e. capacity) to the `List` constructor (since you know what it is). – mjwills Jan 24 '20 at 10:41
0

As you are looking Both List into single List.

Just call the main Class or VM:

//TODO: Populate the data in List.

var singleList = new List<IndustryLandingHeader>();
Shaiju T
  • 6,201
  • 20
  • 104
  • 196
-1

Please try the below :

this.SubIndustries.Concat(this.AdditionalKeyword).ToList() 

List.Concat method creates a new sequence of items from both lists without affecting the original list.

Note that Concat method returns IEnumerable<> collection and so we need to apply ToList() over the output of concat method

Pimenta
  • 1,029
  • 2
  • 13
  • 32
  • Please add a link to your details, this way an user can always double check the terms and read more about a new command. [List.Concat](https://learn.microsoft.com/en-us/dotnet/api/system.linq.enumerable.concat?view=netframework-4.8) – Pimenta Jan 24 '20 at 11:16
  • 1
    Here is the link...https://learn.microsoft.com/en-us/dotnet/api/system.linq.enumerable.concat?view=netframework-4.8 In general any collection implementing IEnumerable supports concat method – Ritesh Kulkarni Jan 24 '20 at 12:15