In: Computer Science
Discuss different ways user input can be validated using .Net and C#. How can you determine the best way to validate user input?
Discuss business problems that could be solved by the implementation of multithreading and asynchronous processing.
explain how "Optimize Applications with Multithreading implementation discussed can improve your C# code.
`Hey,
Note: Brother if you have any queries related the answer please do comment. I would be very happy to resolve all your queries.
1)
"To detect an error while you are parsing an int, you can use the int.TryParse(someString, out result) method. It takes a stringthat you want to convert (or parse) to an int and the result as a parameter. The out keyword in our example means that the result of this method will be written to the second method parameter which we called result. The output of the method is a bool value that indicates whether it was possible to parse the input as an int. Take a look at this example:
Console.WriteLine("Input your age"); var ageAsString = Console.ReadLine(); int age; bool parseSuccess = int.TryParse(ageAsString, out age); if (parseSuccess) Console.WriteLine($"Your age is: {age}"); else Console.WriteLine("This is not a number!");
So, like int we can do for any data type offered by c#
2)
In mobile applications to prevent the freezing of the screen, and give the customer the impression that the process is taking actions visually, but it’s usually not. Literally speaking, when an application asks for data (from a database, webservice, etc.), it has to wait until that service replies. All of the fancy gestures that are usually present in applications happen because of async calls to the services at the same time as entertaining the user with some logo or messaging. The amount of resources used at this time is much higher than normal app usage and ultimately, with lots of refreshes, users’ memory suffers.
There are work-arounds, and async is necessary in instances such as preloading data when the app first begins. In other instances, though, it’s cliché and often to the detriment of the users’ device to utilize async so heavily.
3)
For a long time, most programming applications (except for embedded system programs) were single-threaded. That means there was only one thread in the entire application. You could never do computation A until completing computation B. A program starts at step 1 and continues sequentially (step 2, step 3, step 4) until it hits the final step (call it step 10). A multithreaded application allows you to run several threads, each thread running in its own process. So theoretically you can run step 1 in one thread and at the same time run step 2 in another thread. At the same time you could run step 3 in its own thread, and even step 4 in its own thread. Hence step 1, step 2, step 3, and step 4 would run concurrently. Theoretically, if all four steps took about the same time, you could finish your program in a quarter of the time it takes to run a single thread (assuming you had a 4 processor machine).
Kindly revert for any queries
Thanks.