TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Janaki Ram
NA
5
1.1k
Object reference not set to an instance of an object
Nov 12 2017 12:34 PM
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);
}
}
Reply
Answers (
2
)
I need this Program
Node tree action