22 March 2013

C# -- General Questions and Answers Part-II

C# -- General Questions and Answers:
1)      Is it possible to use Keychar value in Keyup Event?
           Yes, Use Keyvalue.
if (e.KeyValue == 13)
                   MessageBox.Show("Press Enter Key");
22)      Difference between Form_loading and Form_activated?
  Load: This event occurs before a form is displayed for the first time.
  Activated: This event occurs when the form is activated in code or by the user.
33)      What are the Keywords apply to event?
Keywords for Event: Static, Virtual, Sealed and Abstract.
44)      Which is a basis for event?
 Form_Load, Click, Got_Focus (), Set_Focus(),Activate(),Form_Close()
55)      Where to use default keyword?
The default keyword is contextual since it has multiple usages. I am guessing that you are referring to its newer C# 2 meaning in which it returns a type's default value. For reference types this is null and for value types this new instance all zero'd out.
66)      Is it possible to change the const keyword object?
No, you will get this error "The left-hand side of an assignment must be a variable, property or indexer".
77)      Is static modifier allowed in a Constant Declaration? Why?
No, Static and const are not the same thing. Static means that you do not instantiate a class object in memory to use the static object.  Static objects can be changed.
Const means that you cannot change the value.
88)      Is it possible to use more catch statement in the Try catch statement?
                                             //try connect to db
                    catch (SqlException ex)
                        // information of database related exception
                    catch (Exception ex)
                        // catch any other error

99)      What is the default value of bool value?
Boolean default is false
110)   How to stop long Thread?
Use Thread. Stop ();
111)   Which namespace has Threading?
Namespace of Threading is  System. Threading;
112)   How to get Default value in C#.net?
Use Default Keyword.
113)   When are validating and validated events suppressed?
CausesValidation Property is false.
114)   Difference between Double.Parse and Double.TryParse?
Parse throws an exception if it cannot parse the value
 TryParse returns a bool indicating whether it succeeded.
115)   What method do you call on a delegate to run it on a background thread?
  Invoke Method.
116)   What keyword provides thread synchronization?
   Lock Keyword.
117)   Where to use Delegates in C#.net?
Delegates are used in the following cases:
·         Event handlers
·         Callbacks
·         LINQ
·         Implementation of design patterns.

No comments: