I need help with properties - Module Cards numbers | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

I need help with properties - Module Cards numbers

The program that you are given must generate the account number on the bank card. But something is wrong. Create a get property to access the corresponding class member and also set the output. To execute the output you must pass the property to the Console.WriteLine () method. I tried to do it this way but I get an error. This is my code: using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading; using System.Threading.Tasks; namespace SoloLearn { class Program { static void Main(string[] args) { Card card1 = new Card(); //fix the exit Console.WriteLine(card1.accountNum); } } class Card { private string accountNum = "0011592048120"; // create a property to get the account get { return accountNum; } } }

27th Jun 2021, 3:01 AM
Alex Narváez
Alex Narváez - avatar
11 Answers
27th Jun 2021, 12:23 PM
JaScript
JaScript - avatar
+ 5
public string AccountNum { get { return accountNum; } set { accountNum = value; } }
27th Jun 2021, 9:06 AM
JaScript
JaScript - avatar
+ 2
Thank you very much for your help. What I don't understand is why the first letter of AccountNumber is capitalized? I really appreciate your time helping me and solving this little problem.
27th Jun 2021, 12:28 PM
Alex Narváez
Alex Narváez - avatar
+ 2
Welcome Alex. This is the difference to a property and for a secure access. For more information please see here: https://www.sololearn.com/learning/2624/
27th Jun 2021, 12:33 PM
JaScript
JaScript - avatar
+ 1
I appreciate your help and answer, however I already tried with the solution that you gave me but it also generates an error. the problem mentions the following: The program that you are given must generate the account number on the bank card. But something is wrong. Create a get property to access the corresponding class member and also set the output. To execute the output you must pass the property to the Console.WriteLine () method. Therefore, I do not know how to do it.
27th Jun 2021, 11:17 AM
Alex Narváez
Alex Narváez - avatar
+ 1
It will be more easy to help you if you save your code in SL Playground and provide the link here. In addition please read again the lession about this topic. This will help you to understand it. I think you did not correct this line on that as follows: Console.WriteLine(card1.AccountNum);
27th Jun 2021, 11:23 AM
JaScript
JaScript - avatar
+ 1
Also try it that way by changing the output in the Consolé.WriteLine (card1.getAccountNum) method; and returns error. the problem is in the output because it only talks about implementing the get method inside Console.Write. that's why i need help with this
27th Jun 2021, 11:40 AM
Alex Narváez
Alex Narváez - avatar
27th Jun 2021, 11:37 AM
Alex Narváez
Alex Narváez - avatar
0
Please help i get an error using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading; using System.Threading.Tasks; namespace SoloLearn { class Program { static void Main(string[] args) { Card card1 = new Card(); // card1.AccountNum = ""; Console.WriteLine(card1.accountNum); // fix the exit ********* // Console.WriteLine(card1.accountNum); ********* Console.WriteLine(card1.AccountNum); // ******* see property } } class Card { private string accountNum = "0011592048120"; //create a property to get the account //get { return accountNum; } ********* public string AccountNum // ********** property { get { return accountNum; } set { accountNum = value; } } } }
21st Apr 2022, 3:55 AM
Deepak Prajapat
Deepak Prajapat - avatar
0
You have to call the string which is Public . so it has to be in Capitalized account num : Console.WriteLine(card1.AccountNum);
13th Aug 2022, 2:44 PM
alborz ashrafi
alborz ashrafi - avatar
0
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading; using System.Threading.Tasks; namespace SoloLearn { class Program { static void Main(string[] args) { Card card1 = new Card(); //fix the output Console.WriteLine(card1.AccountNum); } } class Card { private string accountNum = "0011592048120"; //create a property to get the account public string AccountNum { get { return accountNum; } set { accountNum = value; } } } }
13th Mar 2024, 10:31 AM
S8ul Yuvraj
S8ul Yuvraj - avatar