C
C#palekf

❔ method

Hello, If I create a method, does the method know about things in the Main method? Or am I supposed to tell the method?
P
Pobiega407d ago
it will not "know" about things in other methods
P
palekf407d ago
how to tell
P
Pobiega407d ago
you'll get compilation errors? 🙂
P
palekf407d ago
how to import a int/string in a other method
D
Doombox407d ago
public void DoThing(string someValue){ } pass what you want to use in the method as a parameter
E
ero407d ago
arguments
P
palekf407d ago
thank you @Ero @Task.WhenAll
P
Pobiega407d ago
E
ero407d ago
they meant "how to tell the method about the variable" not "how to tell that it doesn't work"
P
Pobiega407d ago
P
palekf407d ago
thank you too
E
ero407d ago
what are those warnings though
P
Pobiega407d ago
suggestions (var over int, public could be private). Not relevant to the topic. also, chill with the passive aggressive comments while someone is helping lol
E
ero407d ago
what? what passive aggressive comments
P
Pobiega407d ago
E
ero407d ago
yeah that's just fact and clarification
P
Pobiega407d ago
Read the initial post. I think its a good idea to show the initial state and how to fix the problem
E
ero407d ago
what
P
palekf407d ago
static public int Poop(string countPoopString) { try { int countPoopInt = Int16.Parse(countPoopString); } catch { Console.WriteLine("Konverting dont available"); } return countPoopInt ; }
T
TheRanger407d ago
$code
M
MODiX407d ago
To post C# code type the following: ```cs // code here ``` Get an example by typing $codegif in chat If your code is too long, post it to: https://paste.mod.gg/
T
TheRanger407d ago
odd method name there
P
palekf407d ago
where
T
TheRanger407d ago
u called ur method Poop
P
palekf407d ago
yes
T
TheRanger407d ago
which means this 💩
P
palekf407d ago
and? its dor testing for
T
TheRanger407d ago
so im saying its odd, u asked where
P
palekf407d ago
what means odd
P
Pobiega407d ago
weird, unusual anyways, your code has a problem.. you are declaring a variable in the try that might not succeed. countPoopInt is declared in the wrong "scope" for you to use it as the return
P
palekf407d ago
what do you mean with scope
P
Pobiega407d ago
$scopes
M
MODiX407d ago
scope A {
thing a;
scope B {
thing b;
}
}
scope A {
thing a;
scope B {
thing b;
}
}
thing a is available in scope A and scope B thing b is available only in scope B
P
Pobiega407d ago
anywhere you see {, that creates a new scope } closes the current scope so the stuff inside the try is not availble outside it
P
palekf407d ago
so how to get it outside
P
Pobiega407d ago
You could split the declaration and the assignment so you declare the variable outside the try, and assign to it inside. you'll need to give it a default value thou, in case the try fails
P
palekf407d ago
static public int Poop(string countPoopString) {
int countPoopInt
try {
int countPoopInt = Int16.Parse(countPoopString);
}
catch {
Console.WriteLine("Konverting dont available");
}
return countPoopInt ;
}
static public int Poop(string countPoopString) {
int countPoopInt
try {
int countPoopInt = Int16.Parse(countPoopString);
}
catch {
Console.WriteLine("Konverting dont available");
}
return countPoopInt ;
}
P
Pobiega407d ago
better, but you have duplicate declarations now
T
TheRanger407d ago
Int16 btw
P
Pobiega407d ago
Ah yes, don't use that. just int.Parse instead
P
palekf407d ago
ok
T
TheRanger407d ago
int CountPoopInt; // this is a declaration
CountPoopInt = 1; // this is an assignment
int CountPoopInt = 1; // this is a declaration and assignment combined
int CountPoopInt; // this is a declaration
CountPoopInt = 1; // this is an assignment
int CountPoopInt = 1; // this is a declaration and assignment combined
P
palekf407d ago
that I know, but the parse is not recocnized now
T
TheRanger407d ago
how so? u need to tell us what error messages u see and show us ur current code
P
palekf407d ago
the name "int" isnt there in the actual konext
T
TheRanger407d ago
copy paste the error message
P
palekf407d ago
Im a german so the error message is in german
T
TheRanger407d ago
doesnt matter, i can see the error code number
P
palekf407d ago
CS0103
T
TheRanger407d ago
error message can help too since it can tell which variable it has the issue with and show ur current code
P
palekf407d ago
ok wait
static public int Poop(string countPoopString) {
int countPoopInt;
try {
int countPoopInt = Int.Parse(countPoopString);
}
catch {
Console.WriteLine("Konvertierung nicht möglich");
}
return countPoopInt;
}

}
static public int Poop(string countPoopString) {
int countPoopInt;
try {
int countPoopInt = Int.Parse(countPoopString);
}
catch {
Console.WriteLine("Konvertierung nicht möglich");
}
return countPoopInt;
}

}
T
TheRanger407d ago
its int.Parse(countPoopString); not Int.Parse(countPoopString); i is small
P
palekf407d ago
oh yeah Ill be away for a short time, thank you
A
Accord406d 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
❔ Project structure1. In my Solution there should be only 1 Project right? Unless its a big App 2. I started using fo❔ how to use EF6 in library with no dependancy injection and no startup.csI used EF core power tools to generate DB Context and reverse engineer the models. now I get an erro❔ HeadFirst Design PatternSo I started with this Book today. First problem starts with the Duck Project: and when he tests h✅ EqualityComparerHello, anyone know of this code work ? --> `EqualityComparer<ICollection<myclass>> .Default.Equals❔ error attaching script (unity)this error appears when trying to attach the script, does anyone know how to solve it?❔ i have an app that runs well on my pc but not on other pcsi have an app that runs well on my pc but on when i zip it and bring it to another pc the ui is all yield???```cs public IEnumerable<int> A() { for (int i = 0; i <= 10; i += 2) yield return i; } C# Data Table issuehttps://pastebin.com/DSHwSh0M based on this program, I need to set the values of the `Old PS A11Y S❔ Microsoft Graph SDK - Serializing objectsHello, I am currently working with Microsoft Graph API to work with the Planner. My goal is to backu❔ XML deserialise different types into a single listI'm using the build in XML serialisation library (unless it's with .NET framework?), and I current h❔ Access things from different scene in UnityI have a Class Selector scene that has a Class Selector Script component (MonoBehaviour) attached to❔ C# how do I write an If-statement to handle a button?Hi, I wanted some assistance with writing a If-statement that filters out the zones section in my ap❔ Magnetic Links for application?Hey, does someone have an article/tutorial/explanation how I can develop magnetic links for my appli❔ Show values from a list in a datagridview getting source from bindingsourceHello! I have the following problem: I am currently developing a winforms app with a datagridview th❔ Render email content .NET 7 (razor)I have to reinplement email content rendering, because currently its not looking really good, especi❔ GetAxis wont workpublic class Driver : MonoBehaviour { // Start is called before the first frame update const✅ (SOLVED)Help a Beginneri am following CodeMonkeys 11Hr youtube video on coding a game in unity. I have ran into a issue whe❔ Exclude items from linq query if they contain one from an array of substringsI've got a list of strings, that if they appear anywhere in a linq query column i want to exclude th✅ Comprehension questions (LeetCode Binary Search)Like the title says it's about this puzzle https://leetcode.com/problems/binary-search/description/ ❔ How to create a cubic function calculator that also calculates the minimum and maximum value```c Console.WriteLine("Please enter a, b, c, d for the cubic function ax^3+bx^2+cx+d");