私はイントロコースを取っており、メソッドと配列に導入されるまでは大きな問題はありませんでした。私は、ユーザー入力郵便番号を取ることができる配列の配列検索を実行する方法を理解するのが難しいです。郵便番号のテキストファイル内にあるかどうか確認してください。 もしそうなら、別のテキストファイル "AGI Text File"内にあるインデックスサブスクリプトを確認し、AGI番号を私のagiOutputLabelに出力する必要があります。C#並行配列と順次配列を使用した混乱
誰かが私の誤解を解消したり、私の教科書よりも理にかなっていると私に説明してくれれば、私はそれを感謝します。
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;
namespace AGI_Florida
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
// Creating an array method
private void SetZipArray(int[] zips)
{
}
private void SetAGIArray(double[] agi)
{
}
private void FindAGI(int[] zips, int agi)
{
bool found = false;
int index = 0;
int position = -1;
while (!found && index < zips.Length)
{
if (zips[index] == agi)
{
found = true;
position = index;
}
index++;
}
return;
}
private void getAgiButton_Click(object sender, EventArgs e)
{
try
{
// Initializing the array with 917 spaces
int[] zips = new int[917];
int[] agi = new int[917];
// Pulling array from text file
StreamReader inputFile = File.OpenText("AGI_FL_ZipCodes- 1.txt");
// Setting index to 0 so the loop knows to stop at 917 spaces
int index = 0;
// Running loop
while ((index < zips.Length) && (!inputFile.EndOfStream))
{
// Creating the index from the zip and parsing it
zips[index] = int.Parse(inputFile.ReadLine());
index++;
}
inputFile.Close();
int zipInput;
if (int.TryParse(zipInputTextBox.Text, out zipInput))
{
if (zipInput > 32003 && zipInput < 34997)
{
if (zipInput != -1)
{
MessageBox.Show(agi.ToString());
}
}
else
{
MessageBox.Show("Please enter a valid zip code");
}
}
else
{
MessageBox.Show("Please enter a valid zip code");
zipInputTextBox.Text = " ";
zipInputTextBox.Focus();
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void getAverageAgiButton_Click(object sender, EventArgs e)
{
// initialize new array
double[] agi = new double[917];
StreamReader inputFile = File.OpenText("AGI_FL-1-1.txt");
// Setting index to 0 so the loop knows to stop at 917 spaces
int index = 0;
while ((index < agi.Length) && (!inputFile.EndOfStream))
{
// Creating the index from the zip and parsing it
agi[index] = double.Parse(inputFile.ReadLine());
index++;
}
inputFile.Close();
// create a variable sum
double sum = 0;
// create a loop to read through the text file
for (index = 0; index < agi.Length; index++)
{
// sum the index of values
sum += agi[index];
}
// perform calculations
double averageAgi = sum/(double) agi.Length;
// print to label
agiLabel.Text = averageAgi.ToString("c");
}
}
}
あなたの例は、並列とは関係ありません。あなたが理解していない特定の問題を提出してください。あなたの質問が広すぎて不明瞭なやり方 – Fabio
2つの異なるテキスト行の間を検索するようにパラレルが指定されました。すなわち:郵便番号の値が「郵便番号・fl.txt」である場合 はにFindAGI方法に添字値 リターン添字を見つける ユーザ入力郵便番号 チェックユーザ入力郵便番号値が内部で プリントAGIを「郵便番号FL .TXT」 をゲットユーザー – Nate