Search code examples
c#variable-declarationvariable-initialization

Declare and assign multiple string variables at the same time


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?


Solution

  • 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.