I am working on an issue I do not remember ever having before.
I am using VS2012 C#
When i add using System.IO; to my main program everything works fine, however when I add it to my class file it will not let me use all of the methods.
using System;
using System.Collections.Generic;
using System.IO;
using System.Data.SQLite;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace FoxySearch
{
class FoxySearch
{
File. <<<<----- here i want to add File.Exists("Blablalba")
}
}
For some reason it wont let me add it. As soon as I add the period the intellisense closes and shows no options.When I then type it out myself it shows red and says,
System.IO.File.Exists(string) is a method but is used like a type
You haven’t really given enough code to say for sure, but it sounds like you’re probably trying to write “normal code” directly in a class declaration, instead of in a method or property declaration.
Classes can only include declarations – method declarations, field declarations etc. You can’t write:
etc. The first line is valid as it’s a variable declaration – the second isn’t, as it’s just a method call. If you move the code into a method, then it’s fine:
Additionally, I’d suggest that you revisit your naming – using the same name for a class and a namespace is a bad idea.