-1

i need to print all rows from one table. avoid placing: s.Adress+s.EmployeeID, etc

var query = from x
            in bd.Employees
            where x.City == "London" && x.TitleOfCourtesy == "Mr."
            select x;

foreach(var s in query)
{
  Console.WriteLine(s.Address+"---"+s.EmployeeID);
}
oms
  • 1
  • 1

1 Answers1

1

Console.WriteLine takes params so you can do this:

Console.WriteLine("{0}---{1}", s.Address, s.EmployeeID.ToString());

Or you can use C# 6.0 string interpolation (Note the dollar sign):

Console.WriteLine($"{s.Address}---{s.EmployeeID}");

EDIT

Since you mentioned in the comments:

I want to print all rows from each column from table Employees (Northwind db), without writing each of the columns names

You can do this, imagine you have a class:

public class One
{
    public int Id { get; set; }
    public string Name { get; set; }
}

You can:

// using System.Web.Script.Serialization;
var ser = new JavaScriptSerializer();
var one = ser.Serialize(new One() { Id = 1, Name = "George" });

Console.WriteLine(one);
CodingYoshi
  • 25,467
  • 4
  • 62
  • 64
  • @mjwills The OP added that in the comments after I answered the question. Nonetheless, I edited the answer. Thanks for the heads up. – CodingYoshi Dec 08 '17 at 23:07