C
C#16mo ago
NDOT

✅ how change the values of an object attribute?

see below
29 Replies
Unknown User
Unknown User16mo ago
Message Not Public
Sign In & Join Server To View
NDOT
NDOT16mo ago
public class List_Estrutura_MontarTESTE
{
public int ID { get; set; }
public int LEVEL { get; set; }
public string CÓDIGO { get; set; }
public string DESCRIÇÃO { get; set; }
}
public class List_Estrutura_MontarTESTE
{
public int ID { get; set; }
public int LEVEL { get; set; }
public string CÓDIGO { get; set; }
public string DESCRIÇÃO { get; set; }
}
Unknown User
Unknown User16mo ago
Message Not Public
Sign In & Join Server To View
NDOT
NDOT16mo ago
those are not attributes?
Unknown User
Unknown User16mo ago
Message Not Public
Sign In & Join Server To View
MODiX
MODiX16mo ago
namespace Namespace;

[Attribute]
public class Class
{
public string PublicField;
private bool _privateField;
protected double protectedField;

public int PublicProperty { get; set; }

public Class() {} // Constructor

public void Method(int parameter)
{
var localVariable = parameter;
}
}
namespace Namespace;

[Attribute]
public class Class
{
public string PublicField;
private bool _privateField;
protected double protectedField;

public int PublicProperty { get; set; }

public Class() {} // Constructor

public void Method(int parameter)
{
var localVariable = parameter;
}
}
For C# versions older than 10, see $StructureOld
NDOT
NDOT16mo ago
oh ok so they're classes?
Unknown User
Unknown User16mo ago
Message Not Public
Sign In & Join Server To View
NDOT
NDOT16mo ago
oh ok it's a property, fine thanks but anyway i fill this property with a value, and i want to fill with another one how can i change the value inside a property ? and btw that's pretty awesome i'll save it
circles.png
circles.png16mo ago
thing.property = <value>
NDOT
NDOT16mo ago
idk if i'm using a really older C# version but when i use Thing. it appears just Add an other functions
NDOT
NDOT16mo ago
Jimmacle
Jimmacle16mo ago
CS classes tend to call fields attributes ¯\_(ツ)_/¯ read the error your variable isn't the type you're assuming it is
Thinker
Thinker16mo ago
What type is Estrutura?
NDOT
NDOT16mo ago
List<List_Structure> Structure = new List<List_Structure>();
List<List_Structure> Structure = new List<List_Structure>();
i translated to be easier to read
Jimmacle
Jimmacle16mo ago
it's a list, which means you need to get an item from the list to modify
NDOT
NDOT16mo ago
i think that i got it
while (dtr["CÓDIGO"].ToString() != null)
{
List_Estrutura_MontarTESTE ItensEstru= Estrutura[0];
ItensEstru.COMPRASSOL = 123;
}
while (dtr["CÓDIGO"].ToString() != null)
{
List_Estrutura_MontarTESTE ItensEstru= Estrutura[0];
ItensEstru.COMPRASSOL = 123;
}
Jimmacle
Jimmacle16mo ago
your naming conventions baffle me but otherwise it looks correct
NDOT
NDOT16mo ago
bro i swear to god that if it was my creation i wouldn't put those names
Jimmacle
Jimmacle16mo ago
kek
NDOT
NDOT16mo ago
lol and it's actually really hard to change those horrible names bc the program has like, more than 20 thousand lines ? this one for example is just bad or ugly, but have ones that just doesn't make sense to what they're
Jimmacle
Jimmacle16mo ago
a) that is awful and whoever did that should be punished and b) if it's a self contained program you can easily rename things using built in refactoring tools if you put your cursor over the identifier and hold control while pressing R twice it should bring it up
NDOT
NDOT16mo ago
but that would work in just one file isn't? cause this object appears in a lot of other files i know that Visual Studio have something to change in a lot of files but i never used it
Jimmacle
Jimmacle16mo ago
no, that's the point of refactoring tools they'll find all the places it's used in the solution and rename it everywhere
NDOT
NDOT16mo ago
damn
Jimmacle
Jimmacle16mo ago
i use it constantly (in rider, but VS definitely has the same tool)
NDOT
NDOT16mo ago
that's too much good to be real awesome i'll search about it
Jimmacle
Jimmacle16mo ago
Refactor rename - Visual Studio (Windows)
Learn how to use the Refactor Rename feature to rename identifiers for code symbols, such as fields, local variables, methods, namespaces, properties and types.
Accord
Accord16mo ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server
More Posts