Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/list/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 与使用Aggregate相比,这是一个更好的方法,因为它可以更有效地处理字符串的创建。Select(i=>i)毫无意义,因为它不做任何事情,而且string.Join比使用Aggregate更有效地处理字符串的创建。 static Observation _C#_List_Lambda - Fatal编程技术网

C# 与使用Aggregate相比,这是一个更好的方法,因为它可以更有效地处理字符串的创建。Select(i=>i)毫无意义,因为它不做任何事情,而且string.Join比使用Aggregate更有效地处理字符串的创建。 static Observation

C# 与使用Aggregate相比,这是一个更好的方法,因为它可以更有效地处理字符串的创建。Select(i=>i)毫无意义,因为它不做任何事情,而且string.Join比使用Aggregate更有效地处理字符串的创建。 static Observation ,c#,list,lambda,C#,List,Lambda,与使用Aggregate相比,这是一个更好的方法,因为它可以更有效地处理字符串的创建。Select(i=>i)毫无意义,因为它不做任何事情,而且string.Join比使用Aggregate更有效地处理字符串的创建。 static Observation GetData(string baseUrl, string provider, string key, string sensor) { var client = new RestClient(Stri

与使用
Aggregate
相比,这是一个更好的方法,因为它可以更有效地处理字符串的创建。
Select(i=>i)
毫无意义,因为它不做任何事情,而且
string.Join
比使用
Aggregate
更有效地处理字符串的创建。
static Observation GetData(string baseUrl, string provider, string key, string sensor)
        {
            var client = new RestClient(String.Format("{0}/data/{1}/{2}", baseUrl, provider, sensor));
            client.Timeout = -1;
            var request = new RestRequest(Method.GET);
            request.AddHeader("IDENTITY_KEY", key);
            IRestResponse response = client.Execute(request);
            Console.WriteLine(response.Content);
            
            var observationsModel = JsonSerializer.Deserialize<SentiloResponse>(response.Content, options);
            Console.WriteLine("This is observationsModel:");
            Console.WriteLine(observationsModel);
            Console.WriteLine("This is the outcome of GetData:");
            Console.WriteLine(observationsModel.Observations.FirstOrDefault());
            return observationsModel.Observations.FirstOrDefault();
        }
static void Main(string[] args)
        {
            configuration = JsonSerializer.Deserialize<SentiloConfig>(File.ReadAllText("configuration.json"), options);
            Console.WriteLine("Configuration Loaded");
            
            foreach(var componentMapping in configuration.ComponentMappings)
            {
                var inputComponent = componentMapping.InputComponent;
                Console.WriteLine("Getting data");
                var sensorsContent = inputComponent.Sensors.AsParallel().Select(s =>
                    new SensorContent{
                        Sensor = GetSensorString(s.SensorName),
                        Observations = new List<Observation>() {
                                
                            GetData(
                                    inputComponent.ServerUrl,
                                    inputComponent.Provider,
                                    inputComponent.Token,
                                    GetSensorString(s.SensorName)
                                    )
                                
                        }
                    }
                ).Where(s => s.Observations.First() != null).ToList();
                var myTest = sensorsContent.Select(s => s.Observations.First().Value).ToList();
                var myTest_2 = sensorsContent.Select(s => s.Observations.First().Value.ToList());
                Console.WriteLine(myTest.ToString());
                Console.WriteLine(myTest_2);
                Console.WriteLine("data retrieved");
                if (!sensorsContent.Any())
                {
                    Console.WriteLine("No sensor data for component {0} with sensors: {1}, check configuration", inputComponent.ComponentName, string.Join(",", inputComponent.Sensors.Select(s => s.SensorName)));
                    continue;
                }
                var sensorRequest = new SentiloPutRequest { Sensors = sensorsContent };
                    
            }
            System.Threading.Thread.Sleep(configuration.SendTime*1000);
            
        }
foreach(var value in myTest)
  Console.WriteLine(value);

// or
Console.WriteLine(string.Join(",",myTest));
var myTestString = myTest.Select(i => i).Aggregate((i, j) => i + "," + j);
Console.WriteLine(myTestString)

// Or

myTest.ForEach(x => Console.WriteLine(x));