How to Convert a Procedural Programming into Object-Oriented Programming?

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

Was this solution helpful to you?

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:

Just Added Q & A:

Find solution

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.