Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Concatenating specific properties values of class

Concatenating specific properties values of class

Scheduled Pinned Locked Moved C#
question
8 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    nitin_ion
    wrote on last edited by
    #1

    I have a class public class t1 { public string Name { get; set; } public string rr { get; set; } public string ss { get; set; } public string yy { get; set; } } i am concatenating values of a class like this var yy = string.Join("", typeof(t1).GetProperties().Select(x => x.GetValue(ttt))); i want to remove some of the properties from concatenating how can it be achieved I know that in select i can write x.property name etc.. but how can I do it in one line

    Kornfeld Eliyahu PeterK 1 Reply Last reply
    0
    • N nitin_ion

      I have a class public class t1 { public string Name { get; set; } public string rr { get; set; } public string ss { get; set; } public string yy { get; set; } } i am concatenating values of a class like this var yy = string.Join("", typeof(t1).GetProperties().Select(x => x.GetValue(ttt))); i want to remove some of the properties from concatenating how can it be achieved I know that in select i can write x.property name etc.. but how can I do it in one line

      Kornfeld Eliyahu PeterK Offline
      Kornfeld Eliyahu PeterK Offline
      Kornfeld Eliyahu Peter
      wrote on last edited by
      #2

      You may add some where to your select?

      I'm not questioning your powers of observation; I'm merely remarking upon the paradox of asking a masked man who he is. (V)

      "It never ceases to amaze me that a spacecraft launched in 1977 can be fixed remotely from Earth." ― Brian Cox

      N 1 Reply Last reply
      0
      • Kornfeld Eliyahu PeterK Kornfeld Eliyahu Peter

        You may add some where to your select?

        I'm not questioning your powers of observation; I'm merely remarking upon the paradox of asking a masked man who he is. (V)

        N Offline
        N Offline
        nitin_ion
        wrote on last edited by
        #3

        then it is same as mentioning like this var yy = t1.Name + t1.rr i want to avoid that

        Kornfeld Eliyahu PeterK 1 Reply Last reply
        0
        • N nitin_ion

          then it is same as mentioning like this var yy = t1.Name + t1.rr i want to avoid that

          Kornfeld Eliyahu PeterK Offline
          Kornfeld Eliyahu PeterK Offline
          Kornfeld Eliyahu Peter
          wrote on last edited by
          #4

          I didn't get you...

          I'm not questioning your powers of observation; I'm merely remarking upon the paradox of asking a masked man who he is. (V)

          "It never ceases to amaze me that a spacecraft launched in 1977 can be fixed remotely from Earth." ― Brian Cox

          N 1 Reply Last reply
          0
          • Kornfeld Eliyahu PeterK Kornfeld Eliyahu Peter

            I didn't get you...

            I'm not questioning your powers of observation; I'm merely remarking upon the paradox of asking a masked man who he is. (V)

            N Offline
            N Offline
            nitin_ion
            wrote on last edited by
            #5

            I have a need to concat some property values of a class let's say

            public class t1
            {
            public string Name { get; set; }
            public string rr { get; set; }
            public string ss { get; set; }
            public string yy { get; set; }
            }

            easy way is

            var yy = string.Join("", typeof(t1).GetProperties().Select(x => x.GetValue(ttt)));

            but then it will have all the properties i want a way in which i can specify the properties which i want to exclude from concatenating. one way is i mention all the properties which i want to concat like this

            var yy = t1.Name + t1.rr;

            but then this is old fashioned and i have a class which has 70+ properties so it is laborious i want a shortcut. Hopr i make myself clear

            Kornfeld Eliyahu PeterK 1 Reply Last reply
            0
            • N nitin_ion

              I have a need to concat some property values of a class let's say

              public class t1
              {
              public string Name { get; set; }
              public string rr { get; set; }
              public string ss { get; set; }
              public string yy { get; set; }
              }

              easy way is

              var yy = string.Join("", typeof(t1).GetProperties().Select(x => x.GetValue(ttt)));

              but then it will have all the properties i want a way in which i can specify the properties which i want to exclude from concatenating. one way is i mention all the properties which i want to concat like this

              var yy = t1.Name + t1.rr;

              but then this is old fashioned and i have a class which has 70+ properties so it is laborious i want a shortcut. Hopr i make myself clear

              Kornfeld Eliyahu PeterK Offline
              Kornfeld Eliyahu PeterK Offline
              Kornfeld Eliyahu Peter
              wrote on last edited by
              #6

              So. That what I suggest. Add some where on property name to exclude them... You also can add some custom attribute to the properties you want to access and get only properties that have the specific attribute...

              I'm not questioning your powers of observation; I'm merely remarking upon the paradox of asking a masked man who he is. (V)

              "It never ceases to amaze me that a spacecraft launched in 1977 can be fixed remotely from Earth." ― Brian Cox

              N 1 Reply Last reply
              0
              • Kornfeld Eliyahu PeterK Kornfeld Eliyahu Peter

                So. That what I suggest. Add some where on property name to exclude them... You also can add some custom attribute to the properties you want to access and get only properties that have the specific attribute...

                I'm not questioning your powers of observation; I'm merely remarking upon the paradox of asking a masked man who he is. (V)

                N Offline
                N Offline
                nitin_ion
                wrote on last edited by
                #7

                not sure what you mean can you write a line for the snippet

                Kornfeld Eliyahu PeterK 1 Reply Last reply
                0
                • N nitin_ion

                  not sure what you mean can you write a line for the snippet

                  Kornfeld Eliyahu PeterK Offline
                  Kornfeld Eliyahu PeterK Offline
                  Kornfeld Eliyahu Peter
                  wrote on last edited by
                  #8

                  var oProperties = typeof(t1).GetProperties().Where(oProp => Attribute.IsDefined(oProp, typeof(MyAttribute)));

                  I'm not questioning your powers of observation; I'm merely remarking upon the paradox of asking a masked man who he is. (V)

                  "It never ceases to amaze me that a spacecraft launched in 1977 can be fixed remotely from Earth." ― Brian Cox

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups