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
Chris Anderson
NA
93
9.4k
Cast is redundant. How to use the is statement?
Dec 2 2020 2:14 AM
Why is it saying "Cast is redundant"? If I remove the cast it instead says How can I target and use the is statement "toy is Featuer feather" otherwise?
Working example: Only says "Cast is redundant" by doesn't through any errors.
if
(input == 1 && (
object
)toy
is
Feather feather)
{
Console.WriteLine(
"ba"
);
typeOfToy = feather;
}
Working example: Foreach lets me target the "toy is Feather feather" without any errors. But putting every is statement in a foreach seems overkill?
foreach
(var toy
in
this
.toy)
{
if
(input == 1 && toy
is
Feather feather)
{
Console.WriteLine(
"ba"
);
typeOfToy = feather;
}
}
Not working example: Casting (object) has been removed and through: "An expression of type List
cannot be handled by a pattern of type 'Feather'. Why is that and what's the best practise using my two examples above? Any other ways to solve this?
if
(input == 1 && toy
is
Feather feather)
{
Console.WriteLine(
"ba"
);
typeOfToy = feather;
}
Reply
Answers (
3
)
Show Data using Modal.
lost focus of dynamic text box