when I compile the code below it compiles successfully. But when i run it it gives me the following error: Unhandled Exception: System.NullReferenceException: Object reference not set to
an instance of an object.
What am i doing wrong?
using System.IO;
using System;
using System.Web;
using System.Web.Services;
using System.Web.Caching;
using System.Collections;
using System.Data;
public class weather
{
public static void Main(string[] args)
{
weather wh=new weather();
wh.display();
}
public void display()
{
Cache cache=new Cache();
Console.WriteLine ("compiled ok"
string Source;
// try to retrieve item from cache
// if it's not there, add it
Source =(String) cache["mykey"];
if (Source == null) {
String rawHtml="This is the string i want to cache";
Source = rawHtml;
cache["mykey"] = Source;
Console.WriteLine( "created explicitly"
}
else {
Console.WriteLine( "retrieved from cache"
}
}
}
an instance of an object.
What am i doing wrong?
using System.IO;
using System;
using System.Web;
using System.Web.Services;
using System.Web.Caching;
using System.Collections;
using System.Data;
public class weather
{
public static void Main(string[] args)
{
weather wh=new weather();
wh.display();
}
public void display()
{
Cache cache=new Cache();
Console.WriteLine ("compiled ok"
string Source;
// try to retrieve item from cache
// if it's not there, add it
Source =(String) cache["mykey"];
if (Source == null) {
String rawHtml="This is the string i want to cache";
Source = rawHtml;
cache["mykey"] = Source;
Console.WriteLine( "created explicitly"
}
else {
Console.WriteLine( "retrieved from cache"
}
}
}