c#


the name 'lanesList' does not exist in the current context


static void CreateLanes()
{
for (int i = 0; i < 3; i++)
{
lanesList.Add(new Lanes(i));
}
}
Im new to code and am wondering why it keep giving me this error.
Thanks in advance
You forgot to initialise laneList before add elements to it. Try this code:
static void CreateLanes()
{
List<Lanes> lanesList = new List<Lanes>();
for (int i = 0; i < 3; i++)
{
lanesList.Add(new Lanes(i));
}
}
Or if you initialise it outside of the method you need to pass it as parameter:
static void CreateLanes(List<Lanes> lanesList)
{
for (int i = 0; i < 3; i++)
{
lanesList.Add(new Lanes(i));
}
}

Related Links

column \“Id\” violates not-null constraint"
XML Schema Union getting “string” is not valid for the element error
How to group linq query by dynamic items
How to get name of roles in Views from IdentityUser in asp.net mvc? [duplicate]
Get unique vertices from unity mesh but keep triangels
Azure SDK 2.9 diagnostics exceptions
In Regards to Android On-Screen Keyboard Input
Export Oracle table to New Excel Document
xaml conditional StringFormat
Efficiency of “Eventhandling”
Unable to cancel Async/Awaiting call on button click
ASP.NET MVC 5 folder authorization
Customise error message on asp.net range validator
Dynamically using a ComboBox column in generated DataGrid
Print Document Printer Settings and Print Preview
PRISM resolve interface with factory that uses type to resolve

Categories

HOME
ide
sql-server-2014
ns2
network-programming
highmaps
artifactory
sugarcrm
doctrine2
annyang
box-api
ndepend
mbed
opendaylight
brightway
ofbiz
audio-streaming
minimagick
bug-reporting
android-navigation-drawer
gnu-screen
wai-aria
email-client
ecmascript-2017
struts
datastax-enterprise
workflow-foundation
resx
typeorm
azure-table-storage
dynamics-ax-2012-r3
pypy
r-factor
contextmenustrip
imageprocessor
fastadapter
asp.net-webhooks
cocoa-scripting
campaign-monitor
multi-user
anypoint-studio
redhat-brms
lex
mediastream
cowboy
keychain
pyexcel
compiler-warnings
amazon-rds-aurora
niagara-ax
rivets.js
denodo
noise
cloudconvert
cancan
sharpdevelop
webmatrix
multi-targeting
trusted-computing
msiexec
vertex-shader
sharing
blackberry-webworks
visual-web-developer
require-handlebars
nsoperationqueue
laterjs
phpdesigner
treelist
ooad
kramdown
dnvm
data-representation
teamstudio-unplugged
shunting-yard
uiblureffect
qf-test
gnip
cocos2d-x-2.x
worklight-appcenter
rpt
winrun4j
mixradio
xtify
adabas
static-class
jython-2.5
mmo
boost.build
inflate
m3u
zend-validate
virtual-printer
parallel-python
cinder
excellibrary
fxcopcmd
azure-appfabric
webdb
helios
software-update
high-load

Resources

Encrypt Message