What I am doing wrong in this programming code? C# help?
-
Ok I am new to programming. I wrote a code but when it is compiled, an error is popping up that the name "name' does not exist in the current context. The code is below. Can someone tell me what is wrong in this programming code. using System; struct student_details { public string name; public int marks; public char grade; } class Test { student_details details=new student_details(); public void accept() { Console.WriteLine("Enter you name: "); name=Console.ReadLine(); Console.WriteLine("Enter your marks: "); marks=Convert.ToInt32(Console.ReadLine... Console.WriteLine("Enter your grade: "); grade=Convert.ToChar(Console.ReadLine(... } public void display() { Console.WriteLine("your name is {0}",name); Console.WriteLine("your marks are {0}",marks); Console.WriteLine("your grade is {0}",grade); } public static void Main() { Test obj=new Test(); obj.accept(); obj.display(); } }
-
Answer:
you forget [details.]Name see below code: details.name=Console.ReadLine();
Pritam at Yahoo! Answers Visit the source
Other answers
You'll have to say details.name = Console.ReadLine(); Same goes for marks and grade, at least that's what I'm assuming. I'm mostly familiar with Java, but since C# is very similar to Java, I would advise you to try and use [instance name].[variable] with variables outside your class. So remember: details.name = Console.ReadLine(), details.marks = Convert.ToInt32(Console.ReadLine..... etc
You'll have to say details.name = Console.ReadLine(); Same goes for marks and grade, at least that's what I'm assuming. I'm mostly familiar with Java, but since C# is very similar to Java, I would advise you to try and use [instance name].[variable] with variables outside your class. So remember: details.name = Console.ReadLine(), details.marks = Convert.ToInt32(Console.ReadLine..... etc
Akim
you forget [details.]Name see below code: details.name=Console.ReadLine();
cal
Related Q & A:
- What are the common usage of python programming language?Best solution by quora.com
- How can I run all my selenium tests sequentially in C#?Best solution by Stack Overflow
- I need help on what I need to buy or do.Best solution by Yahoo! Answers
- What is a good college for computer programming?Best solution by Yahoo! Answers
- What jobs can you get in computer programming?Best solution by Yahoo! Answers
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.