4
I have the following class:
public string Nome;
public int Cpf;
public string getNome() {
return Nome;
}
public void setNome(string nome) {
this.Nome = nome;
}
public int getCpf() {
return Cpf;
}
public void setCpf(int cpf) {
this.Cpf = cpf;
}
how can I convert to an array?
I am wanting to create a function for the database where I need to pass only the table name and a Array
or OrderedDictionary
with the mapping of this class, to avoid having to change the query
each time I add a new attribute to it, I have this function in php
and I’m trying to get through to c#
and the first thing I need to do is this php
I use the function implode()
with array_keys()
to separate the keys
name of the fields in the database and the fields that will be inserted in the database. at the end I have a query
thus INSERT INTO {$table} ( {$fields} ) VALUES ( {$values})";
that serves to insert values in any table.
What is your intention? What would you like to be added to the array?
Nome
andCpf
? In what order? These questions are just to show that what you are trying to do may not make much sense.– sergiopereira
I’m building an application and this is for inserting users into
bd
, for while this class has 10 attributes throughout the development I believe I will need to add more information, I have a function that handles the insertion of this data based on the class, I do not want to need to rewrite thequery's
manually each time you add a new attribute to the class by mapping the class using aarray
orOrderedDictionary
.– Hebert Lima
Since you want to do things dynamically, why not do it in PHP? In C#, although it is possible, this is not how it is done. Or even create classes in C#, do it all in array. Not that I think I should do this, but if you’re going to subvert the advantage of language, then subvert everything. If you feel better, use a
Dictionary
where you are classes. There are even other forms, but if it is to do wrong, it is not worth quoting.– Maniero
because the application is in C#, the application is mobile, Here the staff gave me some tips right after I post the result.
– Hebert Lima