I have a structure and an interface, tell me how I can create an instance of this structure.

public struct Card { public long Number { get; set; } public decimal FeeAmount { get; set; } public DateTime Date { get; set; } } public interface IBank { IEnumerable<Card> ChargedFees(); } public class Bank : IBank { public IEnumerable<Bank> ChargedFees() { ***** } } 
  • Card card = new Card (); And your interface method returns an IEnumerable <Card>. a not IEnumerable <Bank> - Andrey

1 answer 1

There are 2 options:

  1. Card val; and then you can assign values ​​to the fields
  2. Through the operator new . In this case, everything will be initialized with default values.
  • in both cases it will be initialized with the default values - Grundy
  • one
    @Grundy, it seems, in the first case, we will not be able to assign values ​​and will scold that the variable needs to be initialized? Not? - iluxa1810
  • Hmm, really . For some reason it seemed that it was possible. - Grundy
  • @Grundy is so, it seems, the CLR initializes the fields in the first case, according to the debugger, but the compiler forbids working with them until the real assignment. Looks made to be consistent with standard meaningful types. - iluxa1810