C#
Creating a new console application C#... and write the code
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication1
{
class Book
{
public string BookName { set; get; }
public int Price { set; get; }
}
class Program
{
static void Main(string[] args)
{
// Method 1 (Create List with completed books)
List<Book> books1 = new List<Book>()
{
new Book() { BookName = "Lord of the Rings", Price = 200 },
new Book() { BookName = "The Three Musketeers", Price = 300 },
new Book() { BookName = "Harry Potter", Price = 400 },
};
// Method 2 (Create List then we add books )
List<Book> books2 = new List<Book>();
books2.Add(new Book() { BookName = "Lord of the Rings", Price = 200 });
books2.Add(new Book() { BookName = "The Three Musketeers", Price = 300 });
books2.Add(new Book() { BookName = "Harry Potter", Price = 400 });
}
}
}
C#
Creating a new console application C#... and write the code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication1
{
struct MyPoint
{
public int X;
public int Y;
}
class Program
{
static void Main(string[] args)
{
// Method 1 (Create List with filled elements MyPoint)
List<MyPoint> points1 = new List<MyPoint>()
{
new MyPoint() { X = 10, Y = 200 },
new MyPoint() { X = 30, Y = 400 },
new MyPoint() { X = 50, Y = 700 },
};
// Method 2 (Create List then add elements MyPoint)
List<MyPoint> points2 = new List<MyPoint>();
points2.Add( new MyPoint() { X = 10, Y = 200 });
points2.Add( new MyPoint() { X = 30, Y = 400 });
points2.Add( new MyPoint() { X = 50, Y = 700 });
}
}
}