Accessing a string from an if function inside of the returned program
Accessing a string from an if function inside of the returned program
Pretty much, I want to use the variable 'username' in the program that the if function returns, however this program is located in my program.cs, and the if function is not.
Wasn't able to get the public static string in the if function, maybe this is obvious to experienced coders but I'm a beginner.
I tested it out by having the console print the variable value, with no success.
The if function:
public class WeeWoo : ChatBot
{
public static Dictionary<string, string> whitelisted;
static WeeWoo()
string json = File.ReadAllText("whitelists/walls.json");
var data = JsonConvert.DeserializeObject<dynamic>(json);
whitelisted = data.ToObject<Dictionary<string, string>>();
public override void GetTextAsync(string text)
string message = "";
string username = "";
text = GetVerbatim(text);
if (text.Contains("-> me"))
text = text.Replace("[", String.Empty).Replace("]", String.Empty).Replace(" -> me", String.Empty);
String args = text.Split(' ');
username = args[1];
message = args[2];
if (message.Equals("weewoo") && (whitelisted.ContainsKey(username)))
Program.WeeWoo();
public static string username;
string username = "";
username
Can you show how Json return the data...
– Saif
Sep 6 '18 at 3:53
pretty sure the issue is here
username = args[1]; , you are trying to assign args[1]; which is null or empty to username, so username will not have any value– Saif
Sep 6 '18 at 4:00
username = args[1];
args[1];
username
username
I got it by removing the
string username = ""; Thank you!– Praise Allah
Sep 6 '18 at 11:39
string username = "";
0
Thanks for contributing an answer to Stack Overflow!
But avoid …
To learn more, see our tips on writing great answers.
Required, but never shown
Required, but never shown
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
I'm not completely sure what you're trying to do, but remove
string username = "";, leave everything else as-is, and try running it again. Or change the constructor to accept a string, and pass inusernamewhen you call it.– User
Sep 6 '18 at 3:45