One of the questions I was asked was that I have a database table with following columns
pid - unique identifier
orderid - varchar(20)
documentid - int
documentpath - varchar(250)
currentLocation - varchar(250)
newlocation - varchar(250)
status - varchar(15)
I have to write a c# app to move the files from currentlocation to newlocation and update status column as either 'SUCCESS' or 'FAILURE'.
This was my answer
Create a List of all the records using linq
Create a command object which would be perform moving files
using foreach, invoke a delegate to move the files -
use endinvoke to capture any exception and update the db accordingly
I was told that command pattern and delegate did not fit the bill here - i was aksed to think and implement a more favorable GoF pattern.
Not sure what they were looking for - In this day and age, do candidates keep a lot of info on head as one always has google to find any answer and come up with solution.
You should thoroughly practice control statements, arrays, functions, object classes, properties, inheritance, abstraction, polymorphism, CLR, CLS, CTS, and strings exception handling to ace C# interview questions and answers for experienced professionals.
You will need to have some understanding of concepts like encapsulation, polymorphism, abstraction, inheritance, interfaces, etc., as C# is an object-oriented programming language. Basic knowledge of C, C++, or Java so you can understand the syntax of C# better.
I sort of agree with Aaronaught's comment above. For a problem like this, sometimes you can overthink it and try to do something more than you actually need to do.
That said, the one GoF pattern that came to mind was "Iterator." In your first statement, you said you would read all the records into a List. The one thing that could be problematic with that is if you had millions of these records. You'd probably want to process them in a more successive fashion, rather than reading the entire list into memory. The Iterator pattern would give you the ability to iterate over the list without having to know the underlying (database) storage/retrieval mechanism. The underlying implementation of the iterator could retrieve one, ten, or a hundred records at a time, and dole them out to the business logic upon request. This would provide some testing benefit as well, because you could test your other "business" logic using a different type of underlying storage (e.g. in-memory list), so that your unit tests would be independent from the database.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With