I suggest you read up on
Object and Collection Initializers - C# Programming Guide | Microsoft Docs[
^] Note that in your case, your :
PostcodeAnywhereBusinessLogic.ValidateBank(sortCode, accountNum);
does not exist in the same class as you are using to make the call.
You could either make the object which you are calling static, or you will need to instantiate a new object of that classes object by doing something like :
PostcodeAnywhereBusinessLogic postcodeAnywhereBusinessLogic = new PostcodeAnywhereBusinessLogic();
And then you can call
postcodeAnywhereBusinessLogic.ValidateBank(sortCode, accountNum);
The following is a crude little application I made for you to test, debug, and learn from, and reading on from this point is optional. Something to note when instantiating objects, and working with statics, and I will use Interfaces as an example here.
If the class that needs instantiating has had values previously set on said object from within its own scope or by another class and when you call new on an object instance, you are creating a new object with all of its defined variables, methods and properties also as new. Let me show you. Notice in our base class, we have :
MessageClassA a = new MessageClassA();
MessageClassB b = new MessageClassB();
If you were to compare them, you will find they are identical (Except for the inner text to identify between each method), or until one of them are changed, or are sent separate parameters. "a" is a new object derivative of MessageClassA, as is "b" for MessageClassB.
By instantiating a new object type, you will be contracting with the new object you just created. And so; any newly created objects with property variables set on object "a" have no effect on object "b" as it is not the same instance body as it was defined with, but a completely new one. For example Paste this code into a test application and you will get a feel for what is happening. Starting with our base class :
public class BaseClass
{
public string XValue { get; set; } = "DefaultValue";
public void ExecuteMe()
{
MessageClassA a = new MessageClassA();
MessageClassB b = new MessageClassB();
LogMessage logMessage = new LogMessage();
BaseClass baseClass = new BaseClass();
baseClass.XValue = "foo";
logMessage.WriteMessage(a, XValue);
logMessage.WriteMessage(b, baseClass.XValue);
}
}
Next we will add our interface which will do the talking for us.
public interface IMessageInterface
{
void WriteMessage(string s);
}
Then add the following two classes. Note, you can paste these all one after the other. But I'll post the full source below anyway.
public class MessageClassA : IMessageInterface
{
public void WriteMessage(string s)
{
Debug.WriteLine($"Message from MessageClassA { s }");
}
}
public class MessageClassB : IMessageInterface
{
public void WriteMessage(string s)
{
Debug.WriteLine($"Message from MessageClassB { s }");
}
}
Completing this little project with our Message Logger class :
public class LogMessage
{
public void WriteMessage(IMessageInterface Message, string v)
{
Message.WriteMessage($": Variable is : {v}");
}
}
To execute this piece of code, you only need a button and paste this inside whichever button you choose. I'm using button 3 :
private void Button3_Click(object sender, EventArgs e)
{
var bc = new BaseClass();
bc.ExecuteMe();
}
Upon running the code, you will notice in the Debugger Console area :
Quote:
Message from MessageClassA : Variable is : DefaultValue
Message from MessageClassB : Variable is : foo
Notice how "MessageClassB" does not print the same variable as "MessageClassA" - That is because they are two separate instances, and each one uses whatever parameters set for that object declaration. If you follow OriginalGriff's analogy, its like walking into a car dealer and buying two cars of exactly the same type.
Except when you get home you replace the red leather bucket seats with white leather bucket seats. It's the same thing with the variables of each object, where the cars are your objects, and the seats are only a parameter of the car.
While learning this assignment it is important to understand the difference between Instantiating and statics, and the difference between the two. It's worth nothing, when working with statics. If an object is declared static, you can
not instantiate that static class or object.
Using a static object is like declaring a global. Its easier to get and set the values of the class and its static properties without the need to instantiate. Using static classes, methods, and properties makes it easier for the calling code being able to call directly on the object type without the need for instantiating at all.
Further more, these rules are true to an extent, so don't get caught out by not understanding the scope of access modifiers. And on a side note; regarding interfaces, it's also worth noting :
Quote:
An interface declaration may declare zero or more members. The members of an interface must be methods, properties, events, or indexers. An interface cannot contain constants, fields, operators, instance constructors, destructors, or types, nor can an interface contain static members of any kind.
All interface members implicitly have public access. It is a compile-time error for interface member declarations to include any modifiers. In particular, interfaces members cannot be declared with the modifiers abstract, public, protected, internal, private, virtual, override, or static.
If you wish to learn more about Interfaces, you may read
Interfaces - C# Programming Guide | Microsoft Docs[
^] or ask a new question on that topic.
I hope this helps you to understand instantiating and statics a little better.
Also be sure you understand the scope of your code by reading up on those
Access Modifiers - C# Programming Guide | Microsoft Docs[
^]
I'm running out of time here, so I will leave this here and I hope this helps you to better understand what to do. :)