Declare and assign multiple string variables at the same time

Mathlight picture Mathlight · Nov 14, 2012 · Viewed 124.3k times · Source

I'm declaring some strings that are empty, so it won't throw errors later on.

I've read that this was the proper way:

string Camnr = Klantnr = Ordernr = Bonnr = Volgnr = Omschrijving = Startdatum = Bonprioriteit = Matsoort = Dikte = Draaibaarheid = Draaiomschrijving = Orderleverdatum = Regeltaakkode = Gebruiksvoorkeur = Regelcamprog = Regeltijd = Orderrelease = "";

But that doesn't work. I get this error: Klantnr does not exist in the current context.

What did I do wrong?

Answer

Habib picture Habib · Nov 14, 2012

You can do it like:

string Camnr, Klantnr, Ordernr, Bonnr, Volgnr;// and so on.
Camnr = Klantnr = Ordernr = Bonnr = Volgnr = string.Empty;

First you have to define the variables and then you can use them.