✅ Hi im a beginner

im trying to make the function that i created in java to C# but i dont know whats the problem
No description
No description
37 Replies
𝙎ō𝙨𝙚𝙞-𝙠𝙞
that is the code im trying to recreate
𝙎ō𝙨𝙚𝙞-𝙠𝙞
This is the C# one
No description
No description
Sir Rufo
Sir Rufo11mo ago
$code
MODiX
MODiX11mo ago
To post C# code type the following: ```cs // code here ``` Get an example by typing $codegif in chat For longer snippets, use: https://paste.mod.gg/
Sir Rufo
Sir Rufo11mo ago
What problem are you talking about?
Buddy
Buddy11mo ago
itemz As seen in the foreach loop
𝙎ō𝙨𝙚𝙞-𝙠𝙞
Even without the foreach it says abt the static thing
Buddy
Buddy11mo ago
$static
MODiX
MODiX11mo ago
In C#, static allows you to have members (classes, methods, etc) that are not tied to any particular instance and are therefore always, globally, accessible. When applying static members, take the following considerations: • If there are to be multiple instances of a class, do not use static • If you need to track state, do not use static • If you are going to have multi threaded workflows, do not use static unless you're aware of the caveats static is best used for stateless methods, extension methods/classes and in areas where you understand the pros/cons. Read more here: https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/static
𝙎ō𝙨𝙚𝙞-𝙠𝙞
Wait I'll sen dss
Buddy
Buddy11mo ago
You call Class.MethodName(); That is only allowed if it is a static method
Buddy
Buddy11mo ago
You want to access the reference then call CallMethod It is the same as in Java, except the for-loop looks different
𝙎ō𝙨𝙚𝙞-𝙠𝙞
I removed the public in the class now it says abt the protection level
Buddy
Buddy11mo ago
foreach (DataType variable in Collection)
{
variable.Foo();
}
foreach (DataType variable in Collection)
{
variable.Foo();
}
Buddy
Buddy11mo ago
Do you know java?
𝙎ō𝙨𝙚𝙞-𝙠𝙞
not entirely, i started the beginner level till using class and stuff but i really want to learn c# more
Sir Rufo
Sir Rufo11mo ago
java and c# are very similar
Buddy
Buddy11mo ago
First, C# does not use ArrayList, it is legacy and should not be used. We use List<T> where T is the type So example List<int> will be a list of integers
𝙎ō𝙨𝙚𝙞-𝙠𝙞
ohh, the thing i want to replicate too is that, when i put 3 variable in 1 whole list then add another list for another 3 variable
Sir Rufo
Sir Rufo11mo ago
It is better to describe the problem you want to solve instead of describing how you want to solve a problem you do not mention
𝙎ō𝙨𝙚𝙞-𝙠𝙞
ok ok
Buddy
Buddy11mo ago
Anything non-static cannot be accessed globally, meaning it cannot be accessed Item.Callitems(); You need a reference. Like myItem.Callitems(); In your foreach loop itemz was the reference
Buddy
Buddy11mo ago
foreach (Item itemz in items)
{
itemz.Callitems();
}
foreach (Item itemz in items)
{
itemz.Callitems();
}
𝙎ō𝙨𝙚𝙞-𝙠𝙞
ok ill try
Buddy
Buddy11mo ago
Replace ArrayList with List<T> Where T is the datatype In your case that would be List<Items>
𝙎ō𝙨𝙚𝙞-𝙠𝙞
Ohhh i can use the class as the T Ok ok i get it now Thank you i thought i can only use string or something, didnt know i can use the class
Buddy
Buddy11mo ago
No, you can use any datatype.
Sir Rufo
Sir Rufo11mo ago
You did it already in the java code
𝙎ō𝙨𝙚𝙞-𝙠𝙞
yeah, its been a while when i did that code so i forgot abt it haha cuz i thought c# and java is different thanks guys
Sir Rufo
Sir Rufo11mo ago
C# is influenced by java and delphi
𝙎ō𝙨𝙚𝙞-𝙠𝙞
how can i conclude this post? ohh thats why
Buddy
Buddy11mo ago
Type /close if you want to close this thread
𝙎ō𝙨𝙚𝙞-𝙠𝙞
Ok ok thank you so much
Want results from more Discord servers?
Add your server