0% found this document useful (0 votes)
17 views

C# Question and Answer

Uploaded by

abdelidhankot95
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views

C# Question and Answer

Uploaded by

abdelidhankot95
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 32

Purpose of main method

•Namespace : Namespace is used to organize your code and


its collection of class, interface ,structs, enums and delegetes.
•Using keyword to define name space.
•Main method is the entry point into your application.
•Four way to declare valid entry point
•1) static void main()
•2)Static void main (string [])
•3)Static int main()
•4)Static int main(string [])
•If we are declare multiple main method then need to specify
in application which method used.
•https://www.youtube.com/watch?v=TuoPYr9csI8
Write data in console
• C# case sensitive programming language
• There are two way to write data
• 1) Concatenation . Like (‘hello’ + name)
• 2) Place holder syntax. Like (‘hello {0}’, name);
https://www.youtube.com/watch?v=6QcHJ33Yr
Yk&list=PLAC325451207E3105&index=2
Built-in types in C#
• https://www.youtube.com/watch?v=y3k5d6xu
b-E&list=PLAC325451207E3105&index=3
• Boolean type – only true or false
• Integral type – int ,unit ,long ,char
• Floating types – float and double
• Decimal types
• String type
Common operator in C#
• https://www.youtube.com/watch?v=xFWwWc
Z74gU&list=PLAC325451207E3105&index=5
• Assignment operator. (=)
• Arithmetic operator. (+,-,*,%)
• Comparison operator.(==,!=,>,>=,<,<=)
• Conditional operator.(&&,||)
• Ternary operator.(?:)
• Null coalescing operator. (??)
Types in C#
• https://www.youtube.com/watch?v=HuLJbiqp
IM0&index=6&list=PLAC325451207E3105
• There are two types in C#
• 1) values type – int ,faloat,double,enum,struct
• 2) Reference type – interface , class ,array etc.
• By default value types are non nullable.
• There are two types of value types
• 1)Nullable 2) Non nullable
Implicit conversion
• https://www.youtube.com/watch?v=IcDaNmGDMoM&li
st=PLAC325451207E3105&index=7
• Implicit conversion done by complier.
• No loss of information if conversion is done
• Not throw error during conversion.
• Int to float implicit conversion is used and will not loss
data.
• Float is much bigger data type to int.
• Example : int i = 10000;
• Float f = I;
• Console.writeline(f)
Explicit Conversion
• higher data type to Lower data type conversion is called
explicit conversion.
• Throw overflow exception.
• There are two way explicit conversion
• 1) type cast operator with opening and closing parenthesis.
• 2) .net framework convert class
• Smaller data type to bigger data type conversion implicit and
higher to lower data type conversion explicit .
• Possibility of over flow exception and loss of information.
Difference between type cast and convert
class
• Type cast did not throw exception , it will
return minimum number of value.
• Example : float to int conversion
• Convert class throw exception if value much
bigger than data type.
• It will throw overflow exception.
Difference between parse and try parse
• Number is string format then user this two
conversion.
• Parse() method throws an exception if it
cannot parse the value.
• Try parse does not throw error return bool
indicating success or failed.
• Use parse() if value valid other wise user try
parse()
Difference between && and & or || and |

• https://www.youtube.com/watch?v=_TIAA-vg
NeY&index=10&list=PLAC325451207E3105
Difference between while and do while
loop
• https://www.youtube.com/watch?v=s7fVZZeN
Xec&list=PLAC325451207E3105&index=14
• While loops check the condition at the
beginning (starting loops)
• Do while loops check condition at the end of
loops.
• Do loop is guaranteed to execute at least one ,
as while loop not.
Difference between for and while loop
• While loop initialization at one place , condition check
another place and variable modifying at another place .
• Where for loop all of this at one place.
• While (condition) return true or false
• {
• increment value ;
• }
• For (i=0; i< length , i++)
• {
• }
Difference between for and for each loop

• For each loop does not throw error .


• For loop throw run time error where mistake
on writing condition.(Index out of range
exception)
Method in C#
• https://www.youtube.com/watch?v=c4hOXIG8yPo&index=1
6&list=PLAC325451207E3105
• Methods are also called as function.
• Method are extremely useful because define logic one and
use it at many time.
• Methods make the maintain of your application easier.
• Structure of method
• [attributes]
• Access-modifiers return-type method-name (parameters)
• {
Method body
• }
Difference between static and instance
method
• When method declaration includes a static modifier,
that method is called static method.
• When no static modifier is present , the method is
called instance method.
• Static method is invoked using class name , where
instance method is invoked using an instance of class.
• Multiple instance of class can be created and each
instances has its own separate method .
• Static method there are no instance of that method
and invoke only one definition of the static method.
Difference type of method parameters
• https://www.youtube.com/watch?v=7xYSFbU
PP0E&index=17&list=PLAC325451207E3105
• 4 types of method parameters
• 1) value parameters
• 2) Reference parameters
• 3) Out parameters
• 4) Parameters Arrays
What is threading ?
• Threading means parallel code execution.
• There are two type
• 1) Foreground thread
• 2) Background thread
• Foreground thread alive until method
execution done .
• Background thread alive until main application
not exist.
Real Need of Delegate
• Delegate means function to a pointer.
• Delegate is representative of communication
between two parties (functions , method).
Difference between throw and throw ex
• Throw send full stack information.
• Throw ex send stack information from throw
method not send full stack information.
Async and await
• Async and await keyword is code marker.
• We cannot write await without async.
• Await hold method execution until process not
finish.
• Release main thread execution.
• Task.run not wait for execution and run as
background.
Use of shadowing
• The use of shadowing is that for existing class
property we cannot change data type.
• We can inherit and change data type using
new keyword.
Deference between String and string
• String and string both are same but it’s alias
name.
Difference between string and string
builder
• String is immutable
• String builder is mutable.
• string Always create fresh memory allocation.
• String builder update existing memory.
• We are using multiple threading then string is
very useful.
Volatile Keyword
• Volatile keyword used in threading.
• Each thread create own local memory.
• There are no synch between local and main
memory .
• So not found updated variable value.
• So using volatile keyword synch local and main
memory data.
IS Vs AS
• Is check variable data type in if condition.
• object s = “shiv”;
• if(s is string )
• {
• }
• As keyword convert variable one type to another
type
• object s = 1234;
• int s1 = s as int ;
IEnumerable Vs IEnumerator
IEnumerable and IQueryable
• IEnumerable get all data from DB and store in
in memory object after filter data.
• Iqueryable filter data on DB.
• Main difference is data filter.
Dynamic Vs Var
• Var is early bounded (compile time check)
• Dynamic is late bounded (run time check)
Out Vs ref
• Ref : First initialize value out side function and
pass value to function after function return
updated value.
• Two way data binding
• Out : Out initialize value inside function and
pass updated value.
• One way data binding.
== Vs .Equals
• == compare object
• object o1 = “test”;
• object o2 = o1;
• if (o1 = o2) always return true because object
are same
• .Equals compare content.
• If string data type then always compare
content.
Type casting
• Type safe : Cannot move one data type to another
data type.
• Conversion : Convert one data type to another data
type using convert class.
• Cast : convert one data type to another data type
using data type
• Implicit casting : no need to define cast from where
to where. No data loss.
• Explicitly Casting : Need to define cast from where
to where cast. Data loss can happen.

You might also like