本文整理汇总了C#中System.IO.StreamReader.DiscardBufferedData方法的典型用法代码示例。如果您正苦于以下问题:C# System.IO.StreamReader.DiscardBufferedData方法的具体用法?C# System.IO.StreamReader.DiscardBufferedData怎么用?C# System.IO.StreamReader.DiscardBufferedData使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.IO.StreamReader
的用法示例。
在下文中一共展示了System.IO.StreamReader.DiscardBufferedData方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Learn
/// <summary>
/// Counting function
/// </summary>
/// <param name="learningData">input csv file</param>
/// <returns>a [3,x] int array contains all counts</returns>
static int[,] Learn(string learningData)
{
int [,] counts;
string[] line;
int[] fields;
int featuresCount;
using (System.IO.StreamReader inFile = new System.IO.StreamReader(learningData))
{
line = inFile.ReadLine().Split(','); // read first line to determine the number of features
featuresCount = line.Length; // number of features
counts = new int[3, featuresCount];
fields = new int[featuresCount];
inFile.BaseStream.Seek(0, System.IO.SeekOrigin.Begin); // reset stream
inFile.DiscardBufferedData();
while (!inFile.EndOfStream)
{
line = inFile.ReadLine().Split(',');
ParseFields(line, fields);
++counts[fields[0], 0]; // increase the respective counts
++counts[2, 0]; //increase the total counts
for (int i = 1; i < featuresCount; ++i)
{
counts[fields[0], i] += fields[i]; // increase the respective counts
counts[2, i] += fields[i]; // increase the total counts
}
}
}
//double[,] learned = new double[2, featuresCount];
//learned[0, 0] = MEstimate(counts[0, 0], counts[2, 0]);
//learned[1, 0] = MEstimate(counts[1, 0], counts[2, 0]);
//for (int i = 1; i < featuresCount; ++i)
//{
// learned[0, i] = MEstimate(counts[0, i], counts[0, 0]);
// learned[1, i] = MEstimate(counts[1, i], counts[1, 0]);
//}
if (debug)
{
PrintArr(counts, debugFile);
//PrintArr(learned, debugFile);
}
return counts;
}
示例2: openEmissions_Click
private void openEmissions_Click(object sender, EventArgs e)
{
// Set filter options and filter index.
openFileDialog.FileName = "";
openFileDialog.Filter = "Emission Files (.emit)|*.emit|All Files (*.*)|*.*";
openFileDialog.FilterIndex = 1;
openFileDialog.Multiselect = false;
// Call the ShowDialog method to show the dialog box.
if (openFileDialog.ShowDialog() == DialogResult.OK)
{
string line;
B = new MySparse2DMatrix();
emissionsSymbols = new Id2Str();
var separator = '\t';
System.IO.StreamReader sr = new System.IO.StreamReader(openFileDialog.FileName);
emissionsRichTextBox.Text = "";
if ((line = sr.ReadLine()) != null)
{
if (line.Split(separator).Length == 1)
separator = ' ';
sr.DiscardBufferedData();
sr.BaseStream.Seek(0, System.IO.SeekOrigin.Begin);
sr.BaseStream.Position = 0;
}
while ((line = sr.ReadLine()) != null)
{
emissionsRichTextBox.Text += line + "\n";
string[] stateValue = line.Split(separator);
if (stateValue.Length == 3)
{
int row = stateSymbols.setId(stateValue[0]);
int col = emissionsSymbols.setId(stateValue[1]);
B.setValue(row, col, Double.Parse(stateValue[2], CultureInfo.InvariantCulture));
}
}
sr.Close();
if (B.Count > 0)
{
buttonCreateHMM.Enabled = true;
openObservationsToolStripMenuItem.Enabled = true;
}
else
{
buttonCreateHMM.Enabled = false;
openObservationsToolStripMenuItem.Enabled = false;
MessageBox.Show("Error! Parsed emissions matrix resulted empty. Check your input file please.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}