That isn't all your code: that code on it's own generates no errors, and runs, doing what you expected it to:
using System;
using System.Collections.Generic;
using System.IO;
public class Program
{
public static void Main()
{
int ans;
Console.Write("2+3+1= ");
ans=Convert.ToInt32(Console.ReadLine());
if(ans==6)
{
Console.WriteLine("Correct");
}
else
{
Console.WriteLine("wrong");
}
}
}
Somewhere else in the same scope in your code, you are declaring something called "ans" - a variable, constant, or even a method!
And don't use Convert methods on user input - they will cause you app to crash if the user enters a non-numeric character. Use the TryParse methods instead:
Int32.TryParse Method (System) | Microsoft Docs[
^]. They return a bool "OK / Failed" result so you can give them another chane.