我正在开发一个Windows项目,我有一年的ComboBox应该包含从1910年到现在的年份.这是我的代码
comboboxYears.DataSource = Enumerable.Range(1910, DateTime.Now.Year).ToList();
Run Code Online (Sandbox Code Playgroud)
但范围不是在1910年到现在之间.相反它在1910年到3924年之间.我在这里做错了什么?
我正在尝试使用方法读取/写入文件ReadByte
。代码正在工作,但我注意到它们在处理后不可用。我无法打开它们。我的图像没有显示。我一次又一次做错了什么。
if (openFileDialog1.ShowDialog() == DialogResult.OK) {
if (saveFileDialog1.ShowDialog() == DialogResult.OK) {
FileStream fsRead =
new FileStream(openFileDialog1.FileName, FileMode.Open);
FileStream fswrite =
new FileStream(saveFileDialog1.FileName, FileMode.Create);
if (fsRead.Position != fsRead.Length) {
byte b = (byte)fsRead.ReadByte();
fswrite.WriteByte(b);
}
}
}
Run Code Online (Sandbox Code Playgroud) 我试图了解如何使用IEnumerator接口及其用途.我有一个实现IEnumerator接口的类.字符串数组传递给构造函数方法.
问题是当我执行代码时,数组未正确列出.应该做的顺序"ali"
,"veli"
,"hatca"
但它在这个顺序控制台上市"veli"
,"hatca"
和-1
.我感到很困惑.我在这做错了什么?你能帮忙吗?
static void Main(string[] args)
{
ogr o = new ogr();
while (o.MoveNext())
{
Console.WriteLine(o.Current.ToString());
}
}
public class ogr: IEnumerator
{
ArrayList array_ = new ArrayList();
string[] names = new string[] {
"ali", "veli", "hatca"
};
public ogr()
{
array_.AddRange(names);
}
public void addOgr(string name)
{
array_.Add(name);
}
int position;
public object Current
{
get
{
if (position >= 0 && position < array_.Count)
{
return …
Run Code Online (Sandbox Code Playgroud)