I am attempting to teach myself C# and could really use some help grasping how to count a list from another .cs file (Note: Most of what I found when searching online made me confused, so I figured it wouldn't hurt to ask a question specific to what I have going on).
Using VSCode, I have the following folders: MAIN (which has Program.cs) \ C#_ASSETS (Which has Class.cs & List.cs)
The Class.cs file contains the following:
namespace CLASSES{
public class ITEM{
public string Name {get;set;}
public string Location {get;set;}
public ITEM(string Name, string Location){
this.Name = Name;
this.Location = Location;
}
}
}
The List.cs file contains the following:
using CLASSES;
namespace MY_LISTS{
public class MY_LIST{
public static void GET_LISTS(){
List<ITEM> LIST_ONE = new List<ITEM>();
var List_Item_1 = new ITEM("Test Name", "Test Location"); LIST_ONE.Add(List_Item_1);
}
}
}
The Program.cs file contains the following:
using CLASSES;
namespace MYCODE{
class Program{
static void Main(string[] args){
int i;
for(i = 1; i <= LIST_ONE.Count; i++){
if(LIST_ONE[i].Location == "Test Location"){
Console.WriteLine("LIST_ONE has an item named: " + LIST_ONE[i].Name + " with a location of: " + LIST_ONE[i].Location);
}
}
}
}
}
Within the Program.cs file, I'm getting the following error in: for(i = 1; i <= LIST_ONE.Count;)
:
The name 'LIST_ONE' does not exist in the current context
Not sure what happened to the answer post I saw, but someone posted this link: .NET Fiddle