C
C#17mo ago
Juliandyce

❔ I cant find the mistake

.Amount gets unterlined
using System.Transactions;
using System.Collections.Generic;
using System;


namespace MyBank
{
class Bank
{
static void Main(string[] args)
{
var account = new BankAccount("Julian", 10000);
Console.WriteLine("Account {0} was createt for {1} with {2}.", account.Number, account.Owner, account.Balance);

}
}
}
namespace Classes
{
public class Transaction
{
public decimal Amount { get; }
public DateTime Date { get; }
public string Notes { get; }

public Transaction(decimal amount, DateTime date, string note)
{
Amount = amount;
Date = date;
Notes = note;
}
}
}
namespace MyBank
{
public class BankAccount
{

public string Number
{
get;
}
public string Owner
{
get;
set;
}
public decimal Balance
{
get
{
decimal balance = 0;
foreach (var item in allTransactions)
{
balance = balance + item.Amount;
}
return balance;
}
}

private static int accountNumberSeed = 0000000001;

private List<Transaction> allTransactions = new List<Transaction>();

public BankAccount(string name, decimal initialBalance)
{
this.Owner = name;
this.Number = accountNumberSeed.ToString();
accountNumberSeed++;
}

public void MakeDeposit(decimal amount, DateTime date, string note)
{
}

public void MakeWithdrawal(decimal amount, DateTime date, string note)
{
}

}
}
using System.Transactions;
using System.Collections.Generic;
using System;


namespace MyBank
{
class Bank
{
static void Main(string[] args)
{
var account = new BankAccount("Julian", 10000);
Console.WriteLine("Account {0} was createt for {1} with {2}.", account.Number, account.Owner, account.Balance);

}
}
}
namespace Classes
{
public class Transaction
{
public decimal Amount { get; }
public DateTime Date { get; }
public string Notes { get; }

public Transaction(decimal amount, DateTime date, string note)
{
Amount = amount;
Date = date;
Notes = note;
}
}
}
namespace MyBank
{
public class BankAccount
{

public string Number
{
get;
}
public string Owner
{
get;
set;
}
public decimal Balance
{
get
{
decimal balance = 0;
foreach (var item in allTransactions)
{
balance = balance + item.Amount;
}
return balance;
}
}

private static int accountNumberSeed = 0000000001;

private List<Transaction> allTransactions = new List<Transaction>();

public BankAccount(string name, decimal initialBalance)
{
this.Owner = name;
this.Number = accountNumberSeed.ToString();
accountNumberSeed++;
}

public void MakeDeposit(decimal amount, DateTime date, string note)
{
}

public void MakeWithdrawal(decimal amount, DateTime date, string note)
{
}

}
}
https://www.youtube.com/watch?v=xLhm3bEG__c&t=222s c# tutorial of .Net
dotnet
YouTube
Object Oriented Programming: Methods and Members | C# 101 [17 of 19]
Learn more ➡️ https://learn.microsoft.com/users/dotnet/collections/yz26f8y64n7k07 Now our objects need data and behaviors. What can our objects DO and what do they HAVE? Let’s learn how to make members and methods with C# and .NET. 👩‍💻 Get the .NET Interactive Notebooks and follow along at home: https://aka.ms/csharp101notebooks 🏫 Free self-...
17 Replies
Buddy
Buddy17mo ago
$details
MODiX
MODiX17mo ago
When you ask a question, make sure you include as much detail as possible. Such as code, the issue you are facing, and what you expect the result to be. Upload code here https://paste.mod.gg/ (see $code for more information on how to paste your code)
Buddy
Buddy17mo ago
Specifically, please show what errors you are getting Something being underlined* isn't sufficient information.
Juliandyce
JuliandyceOP17mo ago
Schweregrad Code Beschreibung Projekt Datei Zeile Spalte Unterdrückungszustand Fehler CS1061 "Transaction" enthält keine Definition für "Amount", und es konnte keine zugängliche Amount-Erweiterungsmethode gefunden werden, die ein erstes Argument vom Typ "Transaction" akzeptiert (möglicherweise fehlt eine using-Direktive oder ein Assemblyverweis). ConsoleApp2 C:\Users\julia\OneDrive\Desktop\C# Projects.Net Curse OOP\ConsoleApp2\BankAccount.cs 55 46 Aktiv oh its german srry
MODiX
MODiX17mo ago
MODiX#0152
Severity Code Description Project File Row Column Suppression State Error CS1061 "Transaction" does not contain a definition for "Amount", and no accessible Amount extension method could be found that accepts an initial argument of type "Transaction" (a using directive or assembly reference may be missing). ConsoleApp2 C:\Users\julia\OneDrive\Desktop\C# Projects.Net Curse OOP\ConsoleApp2\BankAccount.cs 55 46 Active
Quoted by
<@203166497198047232> from #bot-spam (click here)
React with ❌ to remove this embed.
Juliandyce
JuliandyceOP17mo ago
i just copied the tutorial but it doesn't work
SinFluxx
SinFluxx17mo ago
Does the tutorial have the using System.Transactions; line at the top of the file?
Juliandyce
JuliandyceOP17mo ago
dont think so but i i don use it the error Type or namespace name wasn't found
SinFluxx
SinFluxx17mo ago
Correct, beacuse that line was letting you refer to a Class within the System.Transactions namespace that you weren't intending to use This line here: private List<Transaction> allTransactions = new List<Transaction>(); is in your BankAccount class, which is in your MyBank namespace, which means it doesn't know about your Transaction class, because that's in your Classes namespace
Juliandyce
JuliandyceOP17mo ago
i thought if i use public class it can communicate so can it only know about if it is in the same namespace
SinFluxx
SinFluxx17mo ago
They can, but it still can't "see" it (by default) so to speak because it's in a different namespace Correct, you need to tell that class/file to "use" a different namespace
Juliandyce
JuliandyceOP17mo ago
how? do i have to write over it using "this class"
SinFluxx
SinFluxx17mo ago
yeah, in the same way that you have: using System.Collections.Generic; using System; you could also add: using Classes
Juliandyce
JuliandyceOP17mo ago
private List<Classes.Transaction> allTransactions = new List<Classes.Transaction>(); thanks
SinFluxx
SinFluxx17mo ago
or that yes 🙂
Angius
Angius17mo ago
If you really want to make your life more miserable, sure, using fully-qualified names works
Accord
Accord17mo ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server