C
C#2y ago
Tony

❔ Program does not contain static 'Main'

using System.Collections.Specialized;
using System.Security.Cryptography.X509Certificates;
class Player
{
public string _playerName;
public int playerID;
public Player(string playerName, int playerIdentifier)
{
_playerName = playerName;
playerID = playerIdentifier;
}
}
class Program
{
List<Player> Players = new List<Player>();
void banPlayer(string _playerBan)
{
foreach (Player _player in Players)
{
if (_player._playerName == _playerBan)
{
Players.Remove(_player);
Console.WriteLine("ID: " + _player.playerID + " has been removed");
}
}
}
public void Main()
{
string[] input;
while (Players.Count < 5)
{
input = Console.ReadLine().Split(' ');
Player player = new Player(input[0], Int32.Parse(input[1]));
Players.Add(player);
}
banPlayer(Console.ReadLine());

}
}
using System.Collections.Specialized;
using System.Security.Cryptography.X509Certificates;
class Player
{
public string _playerName;
public int playerID;
public Player(string playerName, int playerIdentifier)
{
_playerName = playerName;
playerID = playerIdentifier;
}
}
class Program
{
List<Player> Players = new List<Player>();
void banPlayer(string _playerBan)
{
foreach (Player _player in Players)
{
if (_player._playerName == _playerBan)
{
Players.Remove(_player);
Console.WriteLine("ID: " + _player.playerID + " has been removed");
}
}
}
public void Main()
{
string[] input;
while (Players.Count < 5)
{
input = Console.ReadLine().Split(' ');
Player player = new Player(input[0], Int32.Parse(input[1]));
Players.Add(player);
}
banPlayer(Console.ReadLine());

}
}
9 Replies
Tony
Tony2y ago
and if i make the main function a static i get
HowNiceOfYou
HowNiceOfYou2y ago
Make everything else static then. Easy solution.
using System.Collections.Specialized;
using System.Security.Cryptography.X509Certificates;
class Player
{
public string _playerName;
public int playerID;
public Player(string playerName, int playerIdentifier)
{
_playerName = playerName;
playerID = playerIdentifier;
}
}
class Program
{
static List<Player> Players = new List<Player>();
static void banPlayer(string _playerBan)
{
foreach (Player _player in Players)
{
if (_player._playerName == _playerBan)
{
Players.Remove(_player);
Console.WriteLine("ID: " + _player.playerID + " has been removed");
}
}
}
static void Main()
{
string[] input;
while (Players.Count < 5)
{
input = Console.ReadLine().Split(' ');
Player player = new Player(input[0], Int32.Parse(input[1]));
Players.Add(player);
}
banPlayer(Console.ReadLine());
}
}
using System.Collections.Specialized;
using System.Security.Cryptography.X509Certificates;
class Player
{
public string _playerName;
public int playerID;
public Player(string playerName, int playerIdentifier)
{
_playerName = playerName;
playerID = playerIdentifier;
}
}
class Program
{
static List<Player> Players = new List<Player>();
static void banPlayer(string _playerBan)
{
foreach (Player _player in Players)
{
if (_player._playerName == _playerBan)
{
Players.Remove(_player);
Console.WriteLine("ID: " + _player.playerID + " has been removed");
}
}
}
static void Main()
{
string[] input;
while (Players.Count < 5)
{
input = Console.ReadLine().Split(' ');
Player player = new Player(input[0], Int32.Parse(input[1]));
Players.Add(player);
}
banPlayer(Console.ReadLine());
}
}
Or use that code. It'll work.
Tony
Tony2y ago
what you modified?
HowNiceOfYou
HowNiceOfYou2y ago
Have a look, compare it.
Tony
Tony2y ago
oh u made the function and the list static i don't understand how it works but thanks man
atakancracker
atakancracker2y ago
Since main function is the entry point of the application, it has to be static. Therefore the other defined methods you want to call has to be static as well. https://stackoverflow.com/questions/4124102/whats-a-static-method-in-c
Angius
Angius2y ago
Alternatively, $nonstaticmain
MODiX
MODiX2y ago
class Program
{
// that's all there is in this class
static void Main(string[] args) => new App().Run(args);
}
class Program
{
// that's all there is in this class
static void Main(string[] args) => new App().Run(args);
}
class App
{
public void Run(string[] args)
{
// code that would go into main, goes here
}
}
class App
{
public void Run(string[] args)
{
// code that would go into main, goes here
}
}
Accord
Accord2y 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