私はC#を初めて使用し、使用しようとしていますLinkedList<T>
class News {
private int Id { get; set; }
private string Name { get; set; }
public News (int id, string name) {
Id = id;
Name = name;
}
public string getName() {
return Name;
}
}
class Program {
static void Main(string[] args) {
var newsList = new LinkedList<LinkedListNode<News>>();
newsList.AddLast(new LinkedListNode<News>(new News(1,"News first")));
newsList.AddLast(new LinkedListNode<News>(new News(2, "News second")));
newsList.AddLast(new LinkedListNode<News>(new News(3, "News third")));
}
}
上記のコードを実行すると、newsList
3つのノードが含まれることになります。ここでnode.Previous
とnode.Next
は両方null
です。私は何が間違っているのですか?
=========================================私の実際のコード====== ===================
public ActionResult NewsDetail(int id = 0)
{
var an = db.News
.Select(n => new NewsView
{
Id = n.Id,
Name = n.Name,
Description = n.Description,
IsTop = n.IsTop,
IsDraft = n.IsDraft,
Content = n.Content,
CaruselContentType = n.CaruselContentType,
CaruselFileContent = n.CaruselFileContent,
CaruselFileName = n.CaruselFileName,
CaruselFileSize = n.CaruselFileSize,
NewsPartViews = n.NewsParts
.Select(
np => new NewsPartView
{
Id = np.Id,
SortNumber = np.SortNumber,
IsDraft = np.IsDraft,
Content = np.Content,
NewsId = np.NewsId,
NewsPartImagesPosition = np.NewsPartImagesPosition,
ImagesCols = np.ImagesCols,
ImagesWidth = np.ImagesWidth,
ImagesHeight = np.ImagesHeight,
ImagesBorder = np.ImagesBorder,
ImagesClickEnlarge = np.ImagesClickEnlarge,
NewsPartImageViews = np.NewsPartImages
.Select(
npi => new NewsPartImageView
{
Id = npi.Id
}
)
}
)
});
var newslList = new LinkedList<NewsView>(an);
return View(newslList.Find(newslList.First(view => view.Id == id)));
}