I have two .cs files and I want to use a button to change value of string channel but it calls error CS0236: (A Field Initializer Cannot Reference The Nonstatic Field, Method, Or Property), please help me, I am looking for a solution two days. Thank you.
in Form1.cs I have
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace TwitchChatBot
{
public partial class Form1 : Form
{
string channel;
//this line is a problem
IrcClient irc = new IrcClient("irc.twitch.tv", 6667, "nickname", "password", channel);
and in IrcClient.cs I have
using System;
using System.Collections.Generic;
using System.IO;
using System.Net.Sockets;
using System.Text;
namespace TwitchChatBot
{
public class IrcClient
{
private string userName;
private string channel;
private TcpClient tcpClient;
private StreamReader inputStream;
private StreamWriter outputStream;
public IrcClient(string ip, int port, string userName, string password, string channel)
{
this.userName = userName;
this.channel = channel;
tcpClient = new TcpClient(ip, port);
inputStream = new StreamReader(tcpClient.GetStream());
outputStream = new StreamWriter(tcpClient.GetStream());
outputStream.WriteLine($"PASS {password}");
outputStream.WriteLine($"NICK {userName}");
outputStream.WriteLine($"USER {userName} 8 * :{userName}");
outputStream.WriteLine($"JOIN #{channel}");
outputStream.Flush();
}