I have a problem. I have been following a tutorial, so that I could learn programming with Xamarin. Well now I have this error line, that I have written in the title. Here's the code for you all;
using System.Collections.ObjectModel;
using UIKit;
namespace freesongsforme
{
static void Main(string[] args)
{
var listView = new ListView();
var myTrainers = new ObservableCollection<string>()
{
"Song 1",
"Song 2",
};
listView.ItemsSource = mySongs;
myTrainers.Add("Songsr");
}
The ''main'' part is marked as an error.
A namespace is a declarative region that provides a scope to the identifiers (the names of types, functions, variables, etc) inside it. Namespaces are used to organize code into logical groups and to prevent name collisions that can occur especially when your code base includes multiple libraries.
The namespace keyword is used to declare a scope that contains a set of related objects. You can use a namespace to organize code elements and to create globally unique types.
Error CS0116: A namespace cannot directly contain members such as fields or methods - Unity Forum.
your code needs to be contained within a Class
namespace freesongsforme
{
public class MyClass {
static void Main(string[] args)
{
var listView = new ListView();
var myTrainers = new ObservableCollection<string>() {
"Song 1",
"Song 2",
};
listView.ItemsSource = mySongs;
myTrainers.Add("Songsr");
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With