dogList
is local to the method Main
. What you want to do instead is to place dogList
outside of that scope.
public class Program
{
static List<Dog> dogList = new List<Dog>();
...
Alternately you can send the list into your add method.
More Related Contents:
- C# how to break public Void [closed]
- How to split Fromdate and Todate based on weekdays(Sat,Sun) using linq c#
- what are the methods “public override bool equals(object obj)” and “public override int gethashcode()” doing? [closed]
- How do I clone a generic list in C#?
- IEnumerable vs List – What to Use? How do they work?
- Remove duplicates from a List in C#
- Check whether an array is a subset of another
- Remove items from one list in another
- A method to count occurrences in a list
- Select distinct using linq [duplicate]
- Inheriting from List
- ICollection Vs List in Entity Framework
- Check if a string contains an element from a list (of strings)
- Getting unique items from a list [duplicate]
- Fast way to convert a two dimensional array to a List ( one dimensional )
- Differences between IQueryable, List, IEnumerator?
- How to remove item from list in C#?
- How to make method call another one in classes?
- How to check whether an object has certain method/property?
- Class List Keeps Printing Out As Class Name In Console?
- Are 2 dimensional Lists possible in c#?
- Check if all items are the same in a List
- Select distinct by two properties in a list
- Count property vs Count() method?
- List.Except is not working
- Parallel.ForEach with adding to list
- Method vs Property in C# – what’s the difference [duplicate]
- Why am I getting System.Collections.Generic.List`1[System.String] instead of the list’s contents? [duplicate]
- Eliminate consecutive duplicates of list elements
- Generate List of methods of a class with method types