我正在尝试计算数组列表中每四个值的滚动平均值,并将这些值添加到单独的数组列表中。我的原始数组列表称为 numlist,它包含从 1 到 9 的值
List<int> numlist = new List<int>();
numlist.Add(1);
numlist.Add(2);
numlist.Add(3);
numlist.Add(4);
numlist.Add(5);
numlist.Add(6);
numlist.Add(7);
numlist.Add(8);
numlist.Add(9);
Run Code Online (Sandbox Code Playgroud)
当它计算滚动平均值时,它应该以如下方式进行:
第一平均值 = (1+2+3+4)/4
第二平均值 = (2+3+4+5)/4
第三平均值 = (3+4+5+6)/4
等等
所以第二个数组列表,
List<double> avelist = new List<double>();
Run Code Online (Sandbox Code Playgroud)
应该包含这些值
{2.5, 3.5, 4.5, 5.5, 6.5, 7.5}
Run Code Online (Sandbox Code Playgroud)
我怎样才能做到这一点?
我有一个包含多个值的LinkedHashSet.
LinkedHashSet<String> lhs = new LinkedHashSet<String>();
Run Code Online (Sandbox Code Playgroud)
我想迭代这组值并显示存储在集合中的项目数的前五个值.我使用for循环迭代值并显示数据,见下文:
for (String sent : lhs) {
text.append(sent);
}
Run Code Online (Sandbox Code Playgroud)
这将输出存储在LinkedHashSet中的所有值.我应该对我的代码进行哪些更改,以便仅从集合中获取前5个值.
我正在尝试开发一个 Windows 窗体应用程序,可以使用 Octokit 创建、更新和删除 GitHub 存储库中的文件。
public Form1()
{
InitializeComponent();
var ghClient = new GitHubClient(new ProductHeaderValue("Octokit-Test"));
ghClient.Credentials = new Credentials("-personal access token here-");
// github variables
var owner = "username";
var repo = "repository name";
var branch = "master";
// create file
//var createChangeSet = ghClient.Repository.Content.CreateFile(owner,repo,"path/file2.txt",new CreateFileRequest("File creation", "Hello World!", branch));
// update file
var updateChangeSet = ghClient.Repository.Content.UpdateFile(owner, repo,"path/file2.txt", new UpdateFileRequest("File update","Hello Universe!", "SHA value should be here", branch));
}
Run Code Online (Sandbox Code Playgroud)
首先,我设法创建一个文件(检查注释掉的代码),该文件功能齐全。然后我尝试使用更新该文件,
var updateChangeSet = ghClient.Repository.Content.UpdateFile(owner, repo,"path/file2.txt", new UpdateFileRequest("File update","Hello …Run Code Online (Sandbox Code Playgroud)