C
C#2y ago
NDOT

✅ how change the values of an object attribute?

see below
29 Replies
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
NDOT
NDOTOP2y 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 User2y ago
Message Not Public
Sign In & Join Server To View
NDOT
NDOTOP2y ago
those are not attributes?
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
MODiX
MODiX2y 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
NDOTOP2y ago
oh ok so they're classes?
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
NDOT
NDOTOP2y 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.png2y ago
thing.property = <value>
NDOT
NDOTOP2y ago
idk if i'm using a really older C# version but when i use Thing. it appears just Add an other functions
NDOT
NDOTOP2y ago
Jimmacle
Jimmacle2y ago
CS classes tend to call fields attributes ¯\_(ツ)_/¯ read the error your variable isn't the type you're assuming it is
Thinker
Thinker2y ago
What type is Estrutura?
NDOT
NDOTOP2y 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
Jimmacle2y ago
it's a list, which means you need to get an item from the list to modify
NDOT
NDOTOP2y 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
Jimmacle2y ago
your naming conventions baffle me but otherwise it looks correct
NDOT
NDOTOP2y ago
bro i swear to god that if it was my creation i wouldn't put those names
Jimmacle
Jimmacle2y ago
kek
NDOT
NDOTOP2y 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
Jimmacle2y 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
NDOTOP2y 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
Jimmacle2y 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
NDOTOP2y ago
damn
Jimmacle
Jimmacle2y ago
i use it constantly (in rider, but VS definitely has the same tool)
NDOT
NDOTOP2y ago
that's too much good to be real awesome i'll search about it
Jimmacle
Jimmacle2y 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
Accord2y 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