Hi
IN below codeinstead of Hardcode i want to pass email & password thru variables
C#
var body = @"{" + "\n" +
@" ""email"" : ""[email protected]""," + "\n" +
@" ""password"" : ""T!""" + "\n" +
@"}";Thanks

John IwaszRank #811 · 2.8K reputationPosted Dec 28, 2022, 12:09 PM EST
string email = "myemail"; string password = "mypassword"; var body = "{\n" + $" \"email\" : \"{email}\",\n" + $" \"password\" : \"{password}\"\n" + "}";However; you're better off using Environment.NewLine as that will conform to your operating system.
string email = "myemail"; string password = "mypassword"; var body = "{" + Environment.NewLine + $" \"email\" : \"{email}\"," + Environment.NewLine + $" \"password\" : \"{password}\"" + Environment.NewLine + "}";And if you are using C# 11 and .NET 7, this works:
string email = "myemail"; string password = "mypassword"; var body = """ { "email" : "{email}", "password" : "{password}" ) """;Munib ButtRank #156 · 14.9K reputationPosted Jan 12, 2023, 3:56 PM EST
Use string interpolation as below:
var value1 = "Test";
var val = $"This is a test value = {value1}";
Console.WriteLine(val);
Works with .NET 7/C# 11