There is a function

var result = Messenger.Get(VersionCode.V1, new IPEndPoint(IPAddress.Parse(device.Ip), 161), new OctetString("public"), new List<Variable> { new Variable(new ObjectIdentifier("1.3.6.1.4.1.42019.3.2.2.2.1.1.3.2")), new Variable(new ObjectIdentifier("1.3.6.1.4.1.42019.3.2.2.5.1.1.2.4")), new Variable(new ObjectIdentifier("1.3.6.1.4.1.42019.3.2.2.5.1.1.3.4")) }, 100); 

How do i generate a variable

 new List<Variable> { new Variable(new ObjectIdentifier("1.3.6.1.4.1.42019.3.2.2.2.1.1.3.2")), new Variable(new ObjectIdentifier("1.3.6.1.4.1.42019.3.2.2.5.1.1.2.4")), new Variable(new ObjectIdentifier("1.3.6.1.4.1.42019.3.2.2.5.1.1.3.4")) } 

having a list of OIDs

 List<string> device.OIDs 

?

  • списокОидов.Select(x => new Variable(new ObjectIdentifier(x))); ? - AK
  • 3
    @AK .ToList() . Otherwise, it will be an IEnumerable<Variable> . - user218976
  • Well, yes, I just do not understand what the complexity of the issue. If I don’t understand what the author wants, the author only masters linq. - AK
  • @AK The author, in principle, has just begun to master c # and after the python it is very wild to see such constructions)) - Dmitry Suvorov
  • What is wildness? I'm looking at your code, I think, "why did it take two to wrap a string?" - you put the string in ObjectIdentifier, and then again - already in Variable. Maybe it was necessary to make fifteen more matryoshka classes and say that c # is wild? ;) Something prevented your Get from taking one of the parameters List<string> instead of new List<Variable> ? Or wrap only once, if you need semantics. - AK

1 answer 1

If I correctly understood the question then:

 void Main() { var oidsList = new List<string> { "1.3.6.1.4.1.42019.3.2.2.2.1.1.3.2", "1.3.6.1.4.1.42019.3.2.2.5.1.1.2.4" }; var result = oidsList.Select(x => new Variable(new ObjectIdentifier(x))).ToList(); } // Define other methods and classes here public class ObjectIdentifier { public string MyProperty { get; set; } public ObjectIdentifier(string a) { this.MyProperty = a; } } public class Variable { public string MyProperty { get; set; } public Variable(ObjectIdentifier b) { this.MyProperty = b.MyProperty; } } 

enter image description here

  • And what is your IDE such that IL shows instructions? - user218976
  • @Anamnian, LinqPad any, this is not IDE - Grundy
  • @Anamnian Oh, this is a very wonderful thing - called LinqPad! I highly recommend - this is my daily tool along with Visual Studio. A small lightweight notebook in which I draw small sketches, and then transfer to real projects. - AK
  • @Grundy aha, thanks, recently met a mention of him in one article on Habré, wondering whether to deliver or not. Now I’ll put it right, too lazy to run ildasm.exe each time. - user218976
  • var result = oidsList.Select(x => new Variable(new ObjectIdentifier(x))).ToList(); It works. Those. did this: var result = Messenger.Get(VersionCode.V1, new IPEndPoint(IPAddress.Parse(device.Ip), 161), new OctetString("public"), device.OIDs.Select(x => new Variable(new ObjectIdentifier(x))).ToList(), 100); I can't win a local editor - Dmitry Suvorov