I’ve got the following c# code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace StringTest
{
class Program
{
static void Main(string[] args)
{
String strSQLCode;
strSQLCode = " select rank() over (order by percentagecorrect desc, totalmilliseconds asc) as rank, * "
+= " from view_dg_game_details gd (nolock) "
+= " where gd.gametypeid = {0} "
+= " and gd.numberofrounds = {1} "
+= " and gd.gamevalues = '{2}' ";
}
}
}
For some reason I’m getting an error “The left-hand side of an assignment must be a variable, property or indexer”.
I can’t see what the error is trying to tell me. I’ve commented out the offending line but the error simply moves up a line.
I can get the string concation to working using this method:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace StringTest
{
class Program
{
static void Main(string[] args)
{
String strSQLCode;
strSQLCode = " select rank() over (order by percentagecorrect desc, totalmilliseconds asc) as rank, * ";
strSQLCode = strSQLCode + " from view_dg_game_details gd (nolock) ";
strSQLCode = strSQLCode + " where gd.gametypeid = {0} ";
strSQLCode = strSQLCode + " and gd.numberofrounds = {1} ";
strSQLCode = strSQLCode + " and gd.gamevalues = '{2}' ";
}
}
}
Can someone explain to me what this error is about?
Thanks
Ken
Because you can’t string together
+=operators without repeating the variable that you’re operating on:If you want to declare it as a “long” one liner, just use
+Or, if you don’t want any of that, you could just use a single string literal: