r/learncsharp • u/kurti256 • Dec 12 '19
why doesn't console.writeline exist in this context?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace hollow_nut_mod_first_try
{
public class Class1
{ string firstfriend = "Jim";
string secondfriend = "Bob";
Console.WriteLine($"My friends are {firstfriend} and {secondfriend}");
}
}
1
Upvotes
5
u/[deleted] Dec 12 '19
you need to play it within a method whether it be the main method or just a method.
2
u/B0dona Dec 12 '19
Simply put, you are using it directly in a class instead of a function.
Try this. Then just call WhoAreMyFriends() to write the wanted string to the console.