日期:2014-05-17  浏览次数:20796 次

有关while循环的问题
 ***********************一共2个大问题麻烦明白的高手给解释下谢谢大家了.
问题一.class Program
    {
      static private int asd;
        static void Main(string[] args)
        {
             
            while (asd < 10)
            {
                Console.WriteLine(asd++);
            }

                       Console.ReadKey();
(1)这里asd不用赋值也while也能循环为什么.(2)如果private int asd前不加static的话Main方法里就运行不了为什么.(是因为Main是静态修饰的吗).
****************************问题二. 这个是打印机的while循环问题.
public partial class Form1 : Form
    {
        private string[] lines;
        private int linesprinted;
.....
....

        private void OnPrintPage(object sender, PrintPageEventArgs e)
        {
    int x = e.MarginBounds.Left;
            int y = e.MarginBounds.Top;
            while (linesprinted < lines.Length)
            {
                e.Graphics.DrawString(lines[linesprinted++], textBoxedit.Font, Brushes.Black, x, y);
                y += 15;
                if (y >=e.MarginBounds.Bottom)
                {
                    e.HasMorePages = true;
                    return;
                }
            }
            linesprinted = 0;
            e.HasMorePages = false;

        } 
(1) 为什么linesprinted=0 在while循环的下面也能循环而不报错未附值.如果把linesprinted注释掉的话会有影响吗感觉这个linesprinted=0是多余的;
(2) private int linesprinted 字段直接在类的方法中能用因为字段和方法都不是静态的?如果加static 会有什么影响吗?