using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;namespace Ch11Ex03
{
    public class Primes
    {
        private long min;
        private long max;       
 public Primes()
            : this(2, 100)
/* 这应该是一个构造函数,后面的“this(2, 100)”是什么意思,又是起什么作用? */
        {
        }        public Primes(long minimum, long maximum)
        {
            
if (min < 2)
/* “min”是一个私有的字段,声明时没赋值,在这个方法里面的这个步骤之前也没有赋值,那“min < 2”还有何意义呢? */
            {
                min = 2;
            }
            min = minimum;
            max = maximum;
        }        public IEnumerator GetEnumerator()
        {
            for (long possiblePrime = min; possiblePrime <= max; possiblePrime++)
            {
                bool isPrime = true;
                for (long possibleFactor = 2; possibleFactor <= (long)Math.Floor(Math.Sqrt(possiblePrime)); possibleFactor++)
                {
                    long remainderAfterDivision = possiblePrime % possibleFactor;
                    if (remainderAfterDivision == 0)
                    {
                        isPrime = false;
                        break;
                    }
                }
                if (isPrime)
                {
                    yield return possiblePrime;
                }
            }
        }
    }
}

解决方案 »

  1.   

    this(2,100)
    的意思是调用它本身的另外一个构造函数即下面的:
    public Primes(long minimum, long maximum)
      

  2.   

    using System;
    using System.Collections;
    using System.Collections.Generic;
    using System.Text;namespace Ch11Ex03
    {
        public class Primes
        {
            private long min;
            private long max;       
     public Primes()
                : this(2, 100)
    /* 这应该是一个构造函数,后面的“this(2, 100)”是什么意思,又是起什么作用? */这句话的意思是调用public Primes(long minimum, long maximum)
    这个构造函数
            {
            }        public Primes(long minimum, long maximum)
            {
                
    if (min < 2)
    /* “min”是一个私有的字段,声明时没赋值,在这个方法里面的这个步骤之前也没有赋值,那“min < 2”还有何意义呢? */  这句话我也不知道什么意思,但是变量min 在类初始化的时候也初始化了 默认值是0            {
                    min = 2;
                }
                min = minimum;
                max = maximum;
            }        public IEnumerator GetEnumerator()
            {
                for (long possiblePrime = min; possiblePrime <= max; possiblePrime++)
                {
                    bool isPrime = true;
                    for (long possibleFactor = 2; possibleFactor <= (long)Math.Floor(Math.Sqrt(possiblePrime)); possibleFactor++)
                    {
                        long remainderAfterDivision = possiblePrime % possibleFactor;
                        if (remainderAfterDivision == 0)
                        {
                            isPrime = false;
                            break;
                        }
                    }
                    if (isPrime)
                    {
                        yield return possiblePrime;
                    }
                }
            }
        }
    }
      

  3.   

    1,         public Primes()
                : this(2, 100) 
            {
            }
    will call another constructor Primes(long minimum, long maximum) with minimum = 2 and maximum = 100;2,            if (min < 2)
                {
                    min = 2;
                }
    you are right. the code is wrong.
      

  4.   

    if (min < 2)[/color]/* “min”是一个私有的字段,声明时没赋值,在这个方法里面的这个步骤之前也没有赋值,那“min < 2”还有何意义呢? */理论上来说是如此,这个函数按我的理解是min<2是恒成立的。C#会在构造时把min(整数)初始化为0,如果你没有其它初始化的声明的话。
      

  5.   

    这是书上的代码,可以运行,没有编译错误,而且,也实现了书上说的的功能,并且,在此书的勘误表上也没有发现次代码的错误。
    所以,我想,if (min < 2)应该没有错,只是,我还没有理解其中的意欲