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

Question for ..net

.net question

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)
21 views

Question for ..net

.net question

Uploaded by

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

Questions

Write a single line of code that will create a file and write
the text “I’m doing well so far” to it.
What is the difference between a class and a
structure?
Structure is a value type, we can't assign null to object, but it is not the case for a class.
Class is reference type.
The general difference is that a reference type lives on the heap, and a value type lives stack, that
is, wherever it is your variable or field is defined.
Structure doesn't support inheritance, and polymorphism, but a class supports both.
By default, all the struct members are public but class members are by default private .
Fields are automatically initialized with classes to 0/false/null wheatheras strucutres are not
Conti…

The output will be 20. Value of "b" is a copy of "a", so "b" is unaffected by change of "a.x". But in
class, the output will be 100 because "a" and "b" will reference the same object.
How do you implement conflicting method names
when you inherit off multiple interfaces that
cause the conflict?

https://dotnetfiddle.net/pbwIml , https://dotnetfiddle.net/gweLfL
How do you declare a readonly property in an
interface?
 Only add getter property in interface which is read only

https://dotnetfiddle.net/KBOq1I
What is the difference between the readonly and
const keywords?
ReadOnly : is the keyword whose value we can change during runtime or we can assign it at run
time but only through the non-static constructor.
The value will be initialized only once from the constructor of the class. The difference is that the
value of a static readonly field is set at run time, so it can have a different value for different
executions of the program.
Const : is nothing but "constant", a variable of which the value is constant. And it's mandatory to
assign a value to it. By default a const is static and we cannot change the value of a const
variable throughout the entire program.
However, the value of a const field is set to a compile time constant.
Please write the c# code that will print all the
values in a Dictionary<string, string> instance
Conti…
Dictionary<TKey, TValue> is a generic collection included in the System.Collection.Generics
namespace. TKey denotes the type of key and TValue is the type of TValue.
You can use any valid C# data type for keys and values.
Where is the finally keyword used, and why would
you use it?
It is used optionally with the "try/catch" block and guarantees the execution of any code that
must be executed before exiting the "try" block, regardless of the success or failure of the
application's execution.
The execution of a finally block is intended to release resources, such as database connections,
which are usually available in limited quantities. By this mechanism, the disposal of resources
occurs earlier than the garbage collector's finalization operation, thereby optimizing memory.
Can we have finally without catch? : Yes we can write try {} Finally {} block. In this case
exception will be thrown in try block so finally block will execute always to perform any cleanup
for respective methods.
Define an extension method that will filter a
List<T> based on a custom filter passed as a
parameter.

https://forums.asp.net/t/1735409.aspx?Creating+a+generic+filter+for+IQueryable+collections
What is the difference between sleep and
suspend?
Thread.sleep() sends the current thread into the "Not Runnable" state for some amount of
time. It means thread sleep in 5000 (msec).
Note that sleep is a static method, which means that it always affects the current thread
You should call Thread.sleep() when you actually need a delay in a background thread
t.Suspend() Using it is possible to halt a thread other than the current thread ,suspend means
thread stop when you resume the thread start.
What is base class of all classes in .net framework
?
It is System.Object . It is the base class for all the classes, structures, enumerations, and
delegates in .NET class library.
It defines methods which are available in all classes.Some of these methods are:
Equals(Object) Compares the calling object with another object for equality
ToString() converts the object to string representation
GetHashCode() hashcode of the object
GetType() type of the object
Input GetHashCode GetType ToString Equals
“Hello” -327378614 System.String “Hello”
Int i =13 13 System.Int32 “13”
string a = "Hello"; true
string b = "Hello";
Conti…

https://dotnetfiddle.net/bJV7zu
Data structure to store unique collection apart from
Dictionary ?
Yes , we can use HashSet<T>
What is HashSet in c#?
how can inherit abstract class without
implementing or overriding abstract method ?
Abstract classes can be inherited without implementing the abstract methods (though such a
derived class is abstract itself)yes you can have an "intermediate" class that only implements
some of the abstract methods, but that class must be abstract as well. At some point, when you
get to the concrete class, all abstract methods must be implemented; either in the class itself or
somewhere up the inheritance chain.
Give at least four method name which related
with system.object type ?
Equals(Object) Compares the calling object with another object for equality
ToString() converts the object to string representation
GetHashCode() hashcode of the object
GetType() type of the object
Lazy loading vs eager loading in EF and how to
configure it in MVC ?
Lazy loading :In this loading method, the child objects are not loaded with its parents by
default, we have to make another request to get the child objects. So in the server, data
execution (fetching data) will be happening again and again for every request, hence the speed
of the application will be reduced.
We can control these loading features by setting Context options in our dbContext class.
context.ContextOptions.LazyLoadingEnabled = false;
The above code will disable lazy loading and we will get the parent and child objects in a single
query itself.

http://www.softwareassociates.in/entity-framework-lazy-load-eager-load/
http://www.entityframeworktutorial.net/lazyloading-in-entity-framework.aspx
Lazy loading generated SQL Query
Conti..
Eager Loading: In this loading method, parent and child object loads in a single request .We have to use Include () method to
get the related data of the parent. If we are sure about the data, then use the eager loading method by including the child
property name to its parent.
For example, we have a parent class User

Var query = context. User.Include(“UserDetails “).Take(3);


In the above query, you can see Include command, this query will fetch parent User as well as child UserDetail in a single hit.
http://www.entityframeworktutorial.net/eager-loading-in-entity-framework.aspx
Generated SQL Query for Eager Loading
Linq methods to execute query from database ?
Can Java class call WCF service which is built in NET? If
Yes then how?
Yes , Using wsdl you can call wcf service in to java class below are the steps

Create a WCF Service


Host WCf Service in IIS
Consume WCF Service in Java Client
Create a new Dynamic Web Project in Eclipse:
To create a WS Client, select New > Web Services > select Web Service Client
Enter the WSDL path of the WCF Service
This should auto-generate the code for the WS proxy:
Write the code call wcf service method using service proxy

https://www.codeproject.com/Articles/777036/Consuming-WCF-Service-in-Java-Client
Conti…
Below WCF binding are supported by JAVA class
BasicHttpBinding. Http, Https. Text. None. ...
WSHttpBinding. Http, Https. Text. Message. ...
webHttpBinding Http, Https. Text. Message.

NetTcpBinding do not conform to any public protocol, so it is limited to communication


between .Net components
https://stackoverflow.com/questions/33215220/is-possible-to-access-net-tcp-servicewcf-
through-java-client
https://social.msdn.microsoft.com/Forums/vstudio/en-US/c55e2da2-ec54-431d-8638-11505ba0f
48a/how-do-you-consume-nettcp-by-a-java-client?forum=wcf
Conti..
NetMsmqBinding : his is not an officially supported scenario. But you can find some third party
solutions that enable you to access MSMQ from Java, such as http://javamsmq.codeplex.com/.
It may take more work to make it work with WCF.
What are selectors in CSS ?
Basic selecter
 Type selector :
The CSS type selector matches elements by node name. In other words, it selects all elements of
the given type within a document.
Class selector : Class selector matches elements based on the contents of their class attribute
ID Selector : In an HTML document, the CSS ID selector matches an element based on the value
of its ID attribute. The selected element’s ID attribute must match exactly the value given in the
selector.
 Attribute selector : The CSS attribute selector matches elements based on the presence or
value of a given attribute.
https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Selectors
What makes LINQ statement to force execution?
Using ToList() method to force LINQ query execute immediately
https://weblogs.asp.net/morteza/using-tolist-method-to-force-linq-query-execute-immediately
What is HashSet in c#?
Its colletion like simply adds values in it without checking any duplication. To avoid such a
duplicate data store, .NET provides a collection name set.
This is a set of collection that contains no duplicate elements and there is no specific order for
the elements stored in it.
The HashSet class does not have any maximum capacity for the number of elements stored in
it. This capacity keeps increasing as the number of elements are added in it

http://www.dotnetcurry.com/csharp/1362/hashset-csharp-with-examples
https://dotnetfiddle.net/12oFMF
Conti…

You might also like