Tech
Forums
Jobs
Books
Events
Interviews
Live
More
Learn
Training
Career
Members
Videos
News
Blogs
Login
Sign Up
Ask Question
2
Reply
Object reference not set to an instance of an object
Janaki Ram
Nov 12 2017 12:34 PM
175
Reply
Hi All,
Can anyone one help me to rectify the error for the blow code for String type.
If i pass string directly it is working but if i mention string value1= Console.ReadLine(); not executing.
error:
Unhandled Exception: System.NullReferenceException: Object reference not set to an instance of an object at Program.Main () [0x0000c] in
:0 [ERROR] FATAL UNHANDLED EXCEPTION: System.NullReferenceException: Object reference not set to an instance of an object at Program.Main () [0x0000c] in
:0
C# code:
using System;
public class Program
{
public static void Main()
{
int sp = 0;
int ws = 0;
int di = 0;
string value1= Console.ReadLine();
foreach (char c in value1)
{
if (!char.IsLetterOrDigit(c))
{ sp++;
if(char.IsWhiteSpace(c))
{
sp--;
}
}
if (char.IsWhiteSpace(c))
{ ws++;
}
if (char.IsDigit(c))
{ di++;
}
}
Console.WriteLine("special "+sp);
Console.WriteLine("white "+ws);
Console.WriteLine("digit "+di);
}
}
Upload Source Code
Select only zip and rar file.
Post
Reset
Cancel
Answers (
2
)
Next Recommended Forum
I need this Program
Node tree action