2015-01-20 2 views
-1

내가 친절하게 도움을인스턴스화 수집

namespace MVVM 
{ 
    public class MoviesPageViewModel 
    { 
     public class MoviesPageViewModel 
     { 
      public List<MovieCategory> Items { get; set; } 

      public MoviesPageViewModel() 
      { 
       var movies = new List<Movie> 
          { 
           new Movie {Title = "The Ewok Adventure", Category = "Adventure", Subtitle = "The Towani family civilian shuttlecraft crashes on the forest moon of Endor.", Image = "http://cf2.imgobject.com/t/p/w500/y6HdTlqgcZ6EdsKR1uP03WgBe0C.jpg"}, 
           new Movie {Title = "The In-Laws", Category = "Adventure", Subtitle = "In preparation for his daughter's wedding, dentist Sheldon ", Image = "http://cf2.imgobject.com/t/p/w500/9FlFW9zhuoOpS8frAFR9cCnJ6Sg.jpg"}, 
           new Movie {Title = "The Man Called Flintstone", Category = "Adventure", Subtitle = "In this feature-length film based on the Flintstones TV show", Image = "http://cf2.imgobject.com/t/p/w500/6qyVUkbDBuBOUVVplIDGaQf6jZL.jpg"}, 

           new Movie {Title = "Super Fuzz", Category = "Comedy", Subtitle = "Dave Speed is no ordinary Miami cop--he is an irradiated Miami cop ", Image = "http://cf2.imgobject.com/t/p/w500/bueVXkpCDPX0TlsWd3Uk7QKO3kD.jpg"}, 
           new Movie {Title = "The Knock Out Cop", Category = "Comedy", Subtitle = "This cop doesn't carry a gun - his fist is loaded!", Image = "http://cf2.imgobject.com/t/p/w500/mzlw8rHGUSDobS1MJgz8jXXPM06.jpg"}, 
           new Movie {Title = "Best Worst Movie", Category = "Comedy", Subtitle = "A look at the making of the film Troll 2 (1990) ", Image = "http://cf2.imgobject.com/t/p/w500/5LjbAjkPBUOD9N2QFPSuTyhomx4.jpg"}, 

           new Movie {Title = "The Last Unicorn", Category = "Fantasy", Subtitle = "A brave unicorn and a magician fight an evil king", Image = "http://cf2.imgobject.com/t/p/w500/iO6P5vV1TMwSuisZDtNBDNpOxwR.jpg"}, 
           new Movie {Title = "Blithe Spirit", Category = "Fantasy", Subtitle = "An English mystery novelist invites a medium", Image = "http://cf2.imgobject.com/t/p/w500/gwu4c10lpgHUrMqr9CBNq2FYTpN.jpg"}, 
           new Movie {Title = "Here Comes Mr. Jordan", Category = "Fantasy", Subtitle = "Boxer Joe Pendleton, flying to his next fight", Image = "http://cf2.imgobject.com/t/p/w500/9cnWl7inQVX6wznjYNmQmJXVD6J.jpg"}, 
          }; 

       var moviesByCategories = movies.GroupBy(x => x.Category).Select(x => new MovieCategory { Title = x.Key, Items = x.ToList() }); 

       Items = moviesByCategories.ToList(); 
      } 
     } 

     public class Movie 
     { 
      public string Title { get; set; } 
      public string Subtitle { get; set; } 
      public string Image { get; set; } 
      public string Category { get; set; } 
     } 

     public class MovieCategory 
     { 
      public string Title { get; set; } 
      public List<Movie> Items { get; set; } 
     } 
    } 
} 

"멤버 이름들이 둘러싸는 형식과 동일 할 수 없습니다"그러나 나는이 오류를 데 클래스 생성자에서 객체의 컬렉션을 인스턴스화하는 것을 시도하고있다

+0

두 개의 'MoviesPageViewModel'이 하나씩 있습니다. .NET에서는 허용되지 않습니다. – dotctor

답변

1

당신은 MoviesPageViewModel라는 클래스 당신이 원하는 것을 아마도 아닌 MoviesPageViewModel의 내부 클래스로 선언합니다.

1
public class MoviesPageViewModel 
{ 
    public class MoviesPageViewModel 

이것은 생성자가 아니며 내부 유형입니다. 허용되지 않습니다.

시도 :

public class MoviesPageViewModel 
{ 
    public MoviesPageViewModel(){ 
    ... 
    } 
} 
2

귀하의 중첩 된 클래스는 선언 된 클래스와 같은 이름을 가지고는 할 수 없습니다 :.

public class MoviesPageViewModel 
    { 
     public class MoviesPageViewModel 
     { 

그냥 첫 번째를 제거하거나 그런 식으로 변경 :

public class MoviesPageViewModel 
    { 
     public class OtherClassName 
     { 
1

어떤 이유로 MoviesPageViewModel 클래스 (typo?)가 두 가지로 선언되어 있습니다. 하나 제거 :

namespace MVVM 
{ 
    public class MoviesPageViewModel 
    { 
     public List<MovieCategory> Items { get; set; } 

     public MoviesPageViewModel() 
     {