c# - Return object only if object could be properly created -
I am very new to C # programming and I am struggling with OOP a little bit.
I have created a class with the method that analyzes a text file and creates an object based on its content. I want this function to return an object, which contains some information from the text file, only if the text file is in the correct format.
I call the function to analyze the text file like this:
PokerHand newhand; NewHand = new poker hand (); AnalyzePokerHand.importHand ("C: \\ text.txt"); NewHand = Analysis PokerHand.getAnalyzedHand; If text.txt is not a poker hand history file, or wrong format etc, then I do not want to fill it with newHand Information of What happens correctly if I want to pass the path to a text file and only return the object with information about the hand only if the function is successful?
Take a look!
If you want to indicate that no data is available, then returning the tap is best The way. The second advantage of this approach is that if you try to use member variables, then this zero indicator will throw exceptions.
Comments
Post a Comment