C
C#•12mo ago
Kushiwushi

How do I use a string from one class to another?

c#
using System;
using System.Net.Http;
using System.Threading.Tasks;

public class Keys {
public static void Main (string[] args) {

public string APIKey = "Key";

public string URL = $"example.com/key={APIKey}";

}
}

class Call {
static async Task Main(string[] args) {
using (HttpClient client = new HttpClient()) {
HttpResponseMessage response = await client.GetAsync(Keys.URL);
string result = await response.Content.ReadAsStringAsync();
Console.WriteLine(result);
}

}
}
c#
using System;
using System.Net.Http;
using System.Threading.Tasks;

public class Keys {
public static void Main (string[] args) {

public string APIKey = "Key";

public string URL = $"example.com/key={APIKey}";

}
}

class Call {
static async Task Main(string[] args) {
using (HttpClient client = new HttpClient()) {
HttpResponseMessage response = await client.GetAsync(Keys.URL);
string result = await response.Content.ReadAsStringAsync();
Console.WriteLine(result);
}

}
}
with something like this, how can I use
URL
URL
which is on
Keys
Keys
unto
Call
Call
?
5 Replies
PixxelKick
PixxelKick•12mo ago
Normal Classes need an instance of them made, or, need to be static if only 1 version of them will exist across the system You also only should be declaring the Main function on your entry point class, usually named Program
Kushiwushi
KushiwushiOP•12mo ago
what should I declare on the
Keys
Keys
class then?
PixxelKick
PixxelKick•12mo ago
Properties - C# Programming Guide - C#
A property in C# is a member that uses accessor methods to read, write, or compute the value of a private field as if it were a public data member.
PixxelKick
PixxelKick•12mo ago
Sounds like you wanna be declaring properties on your Keys object 🙂
Kushiwushi
KushiwushiOP•12mo ago
Thanks!
Want results from more Discord servers?
Add your server