问题一:
什么情况下我们使用自动属性功能,生成自动属性时内部没有明确的私有变量那么我们如何访问这个私有变量呢?
 如果不能那我们的封装还有什么存在的意义?

 Code
Code1

 /**//// <summary>
 /**//// <summary>2
 /// net 2.0中使用的方法来定义Email类
    /// net 2.0中使用的方法来定义Email类3
 /// </summary>
    /// </summary>4
 public class Email20
    public class Email205

 
     {
{6
 
        7
 private string _EmailAddress;
        private string _EmailAddress;8
 public string  EmailAddress
        public string  EmailAddress9

 
         {
{10

 set
            set  {_EmailAddress=value ;}
{_EmailAddress=value ;}11

 get
            get  {return _EmailAddress;}
{return _EmailAddress;}12
 }
        }13
 public static bool IsValid(Email20 _Email)
        public static bool IsValid(Email20 _Email)14

 
         {
{15
 Regex regex = new Regex(@"^[\w-\.]+@(\w+\.)+[\w-]{2,4}$");
            Regex regex = new Regex(@"^[\w-\.]+@(\w+\.)+[\w-]{2,4}$");16
 return regex.IsMatch(_Email._EmailAddress);
            return regex.IsMatch(_Email._EmailAddress);17
 }
        }18
 }
    }19

20

21
 //set方法的中间代码
    //set方法的中间代码22

23
 //    .method public hidebysig specialname instance void
    //    .method public hidebysig specialname instance void 24
 //        set_EmailAddress(string 'value') cil managed
    //        set_EmailAddress(string 'value') cil managed25
 //{
    //{26
 //  // 代码大小       9 (0x9)
    //  // 代码大小       9 (0x9)27
 //  .maxstack  8
    //  .maxstack  828
 //  IL_0000:  nop
    //  IL_0000:  nop29
 //  IL_0001:  ldarg.0
    //  IL_0001:  ldarg.030
 //  IL_0002:  ldarg.1
    //  IL_0002:  ldarg.131
 //  IL_0003:  stfld      string linq1.Email20::_EmailAddress
    //  IL_0003:  stfld      string linq1.Email20::_EmailAddress32
 //  IL_0008:  ret
    //  IL_0008:  ret33
 //} // end of method Email20::set_EmailAddress
    //} // end of method Email20::set_EmailAddress34

35
 //Get方法的中间代码
    //Get方法的中间代码36

37
 //.method public hidebysig specialname instance string
    //.method public hidebysig specialname instance string 38
 //        get_EmailAddress() cil managed
    //        get_EmailAddress() cil managed39
 //{
    //{40
 //  // 代码大小       12 (0xc)
    //  // 代码大小       12 (0xc)41
 //  .maxstack  1
    //  .maxstack  142
 //  .locals init ([0] string CS$1$0000)
    //  .locals init ([0] string CS$1$0000)43
 //  IL_0000:  nop
    //  IL_0000:  nop44
 //  IL_0001:  ldarg.0
    //  IL_0001:  ldarg.045
 //  IL_0002:  ldfld      string linq1.Email20::_EmailAddress
    //  IL_0002:  ldfld      string linq1.Email20::_EmailAddress46
 //  IL_0007:  stloc.0
    //  IL_0007:  stloc.047
 //  IL_0008:  br.s       IL_000a
    //  IL_0008:  br.s       IL_000a48
 //  IL_000a:  ldloc.0
    //  IL_000a:  ldloc.049
 //  IL_000b:  ret
    //  IL_000b:  ret50
 //} // end of method Email20::get_EmailAddress
    //} // end of method Email20::get_EmailAddress51

52

53

54

55

56

57

58

 /**//// <summary>
    /**//// <summary>59
 /// net 3.5 中使用方法来定义Email类
    /// net 3.5 中使用方法来定义Email类60
 /// </summary>
    /// </summary>61
 public class Email35
    public class Email3562

 
     {
{63

 /**//// <summary>
        /**//// <summary>64
 /// net 3.5的属性的简略写法(称其为自动属性 Auto Implemented Properties)
        /// net 3.5的属性的简略写法(称其为自动属性 Auto Implemented Properties)65
 /// </summary>
        /// </summary>66

67

 public string EmailAddress
        public string EmailAddress  { set; get; }
{ set; get; }68

69
 //使用扩展方法后这些函数就没必要搁在这里了 见Extensions
        //使用扩展方法后这些函数就没必要搁在这里了 见Extensions70
 //public static bool IsValid()
        //public static bool IsValid()71
 //{
        //{72
 
 73
 //}
        //}74
 }
    }75

76
 //get自动属性生成的中间代码
    //get自动属性生成的中间代码77

78
 //.method public hidebysig specialname instance string
    //.method public hidebysig specialname instance string 79
 //        get_EmailAddress() cil managed
    //        get_EmailAddress() cil managed80
 //{
    //{81
 //  .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 )
    //  .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) 82
 //  // 代码大小       11 (0xb)
    //  // 代码大小       11 (0xb)83
 //  .maxstack  1
    //  .maxstack  184
 //  .locals init (string V_0)
    //  .locals init (string V_0)85
 //  IL_0000:  ldarg.0
    //  IL_0000:  ldarg.086
 //  IL_0001:  ldfld      string linq1.Email35::'<EmailAddress>k__BackingField'
    //  IL_0001:  ldfld      string linq1.Email35::'<EmailAddress>k__BackingField'87
 //  IL_0006:  stloc.0
    //  IL_0006:  stloc.088
 //  IL_0007:  br.s       IL_0009
    //  IL_0007:  br.s       IL_000989
 //  IL_0009:  ldloc.0
    //  IL_0009:  ldloc.090
 //  IL_000a:  ret
    //  IL_000a:  ret91
 //} // end of method Email35::get_EmailAddress
    //} // end of method Email35::get_EmailAddress92

93
 //set自动属性生成的中间代码
    //set自动属性生成的中间代码94

95
 //.method public hidebysig specialname instance void
    //.method public hidebysig specialname instance void 96
 //        set_EmailAddress(string 'value') cil managed
    //        set_EmailAddress(string 'value') cil managed97
 //{
    //{98
 //  .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 )
    //  .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) 99
 //  // 代码大小       8 (0x8)
    //  // 代码大小       8 (0x8)100
 //  .maxstack  8
    //  .maxstack  8101
 //  IL_0000:  ldarg.0
    //  IL_0000:  ldarg.0102
 //  IL_0001:  ldarg.1
    //  IL_0001:  ldarg.1103
 //  IL_0002:  stfld      string linq1.Email35::'<EmailAddress>k__BackingField'
    //  IL_0002:  stfld      string linq1.Email35::'<EmailAddress>k__BackingField'104
 //  IL_0007:  ret
    //  IL_0007:  ret105
 //} // end of method Email35::set_EmailAddress
    //} // end of method Email35::set_EmailAddress106

107

问题2:
查找每个类别中单价最高的产品:(其实这样做是达不到直接显示结果的要求的)
 在gridview中没法显示出来。

 Code
Code1
 var categories =
var categories =2
 from p in db.Products
    from p in db.Products3
 group p by p.CategoryID into g
    group p by p.CategoryID into g4

 select new
    select new  {
{5
 g.Key,
        g.Key,6
 MostExpensiveProducts =
        MostExpensiveProducts =7
 from p2 in g
            from p2 in g8
 where p2.UnitPrice == g.Max(p3 => p3.UnitPrice)
            where p2.UnitPrice == g.Max(p3 => p3.UnitPrice)9
 select p2
            select p210
 };
    };11

问题3:
下面这两行代码怎么得到的结果是一个为什么结怎么有一个Length列呢(只是字符内容的长度)

 Code
Code1

 var citys = from p in db.Customers select new
var citys = from p in db.Customers select new  { p.Country,p.City };
{ p.Country,p.City };2
 this.dataGridView1.DataSource = citys;
this.dataGridView1.DataSource = citys;3
