What Is The Class Used For Dealing With Graphics Objects: Puneet20884 Show/Hide Answer
What Is The Class Used For Dealing With Graphics Objects: Puneet20884 Show/Hide Answer
What Is The Class Used For Dealing With Graphics Objects: Puneet20884 Show/Hide Answer
We can also set Image path during the Initilization of Bitmap Object. Code as given
below.
Bitmap loBMP = new Bitmap(strPath);
Modified By:
Moderator3
How we can gt the values of control on the previous page in case od server.transfer
method?
Posted by: Lakhangarg | Show/Hide Answer
Using Page.PreviousPage.FindControl() method.
Can we use Page.PreviousPage to get the value of controls of the previous page in
case of response.Redirect ?
Posted by: Lakhangarg | Show/Hide Answer
No, we can't use PreviousPage to find the control on previous page with
response.redirect.
What is the page size in SQL Server?
Posted by: Lakhangarg | Show/Hide Answer
8 KB -- > 8192
you can check this with the query :
SELECT low FROM master..spt_values WHERE number = 1 AND type = 'E'
What is the main difference between RegisterStartUpScript and
RegisterClientScriptBlock?
Posted by: Lakhangarg | Show/Hide Answer
RegisterStartUpScript Add the javascript code at the end of the page before the closing of
form tag. while RegisterClientScriptBlock place the code at th top of the page.
Which methods are used to execute javascript code from code behind file?
Posted by: Lakhangarg | Show/Hide Answer
RegisterStartupScript and RegisterClientScriptBlock
If i will write a piece of code in finaly block, will it execute if there is an exception in
try block.
Posted by: Lakhangarg | Show/Hide Answer
Yes, the code in finally block will execute.
Why 'static' keyword is used before Main()?
Posted by: Abhisek | Show/Hide Answer
Program execution starts from Main(). S it should be called before the creation of any
object. By using static the Main() can now be called directly through the class name and
there is no need to create the object to call it. So Main() is declared as static.
What is CharEnumerator in C#?
Posted by: Raja | Show/Hide Answer
CharEnumerator is an object in C# that can be used to enumerate through all the
characters of a string. Below is the sample to do that
while(chs.MoveNext())
Response.Write(chs.Current);
Moderator: please do not move this to Code section, this is a typical interview question
that was asked :)
I would like to find all the directories of a folder How should I achieve this?
Posted by: Nishithraj | Show/Hide Answer
By Directory.GetDirectories method
}
What is the use of param keyword in C#?
Posted by: Abhisek | Show/Hide Answer
In C# param parameter allows us to create a method that may be sent to a set of
identically typed arguments as a single logical parameter.
Which class defines different events for controls in C#?
Posted by: Abhisek | Show/Hide Answer
The "Control" class defines a number of events that are common to many controls.
What do you mean by properties in C#?
Posted by: Abhisek | Show/Hide Answer
Property acts as a cross link between the field and the method . Actually it behaves as
a field. We can retrieve and store data from the field using property.
The compiler automatically translates the field like property into a call like special
method called as 'accessor" . In property there are two accessor and that are used to save
value and retrieve value from the field. The two properties are 'get' and 'set'.
The get property is used to retrieve a value from the field and the set property is used to
assign a value to a field .
ReadWrite Property :- When both get and set properties are present it is called as
ReadWrite Property.
ReadOnly Property :- When there is only get accessor it is called as ReadOnly Property.
#if , #elif , #else , #endif :- These are used to conditionally skip sections of source code.
What is the use of GetInvocationList() in C# delegates?
Posted by: Abhisek | Show/Hide Answer
GetInvocationList() returns an array of System.Delegate types, each representing a
particular method that may be invoked.
C# delegate keyword is derived form which namespace?
Posted by: Abhisek | Show/Hide Answer
C# delegate keyword is derived form System.MulticastDelegate.
What will be the length of string type variable which is just declared but not
assigned any value?
Posted by: Virendradugar | Show/Hide Answer
As variable is not initialized and it is of reference type. So it's length will be null and it
will throw a run time exception of "System.NullReferenceException" type, if used.
How do we retrieve day, month and year from the datetime value in C#?
Posted by: Nishithraj | Show/Hide Answer
Using the methods Day,Month and Year as follows
nt year = dobDate.Year;
I need to restrict a class by creating only one object throughout the application.
How can I achieve this?
Posted by: Nishithraj | Show/Hide Answer
We can declare the constructor of the class as either protected or as private
int? d = 1; Type testType = d.GetType(); will result…
Posted by: Bhakti | Show/Hide Answer
NOTE: This is objective type question, Please click question title for correct answer.
How can you make your machine shutdown from your program?
Posted by: Bhakti | Show/Hide Answer
Process.Start("shutdown", "-s -f -t 0");
What is the use of unsafe keyword in C#?
Posted by: Abhisek | Show/Hide Answer
In C# the value can be directly referenced to a variable, so there is no need of pointer.
Use of pointer sometime crashes the application. But C# supports pointer, that means we
can use pointer in C#.
Example:-
unsafe
{
int a, *b;
a = 25;
b = &a;
Console.WriteLine("b= {0}",b);//returns b= 25
}
What is difference between var and Dynamic ?
Posted by: Bhakti | Show/Hide Answer
Var word was introduced with C#3.5(specifically for LINQ) while dynamic is introduced
in C#4.0. variables declared with var keyword will get compiled and you can have all its
related methods by intellisense while variables declared with dynamic keyword will
never get compiled. All the exceptions related to dynamic type variables can only be
caught at runtime.
What is dynamic keyword ?
Posted by: Bhakti | Show/Hide Answer
Its newly introduced keyword of C#4.0. To indicate that all operations will be performed
runtime.
What will happen if you declare a variable named "checked" with any data type?
Posted by: Virendradugar | Show/Hide Answer
Compiler will throw an error as checked is a keyword in C# So It cannot be used as
variable name. Checked keyword is used to check the overflow arithmetic checking.
What are anonymous methods?
Posted by: Bhakti | Show/Hide Answer
Anonymous methods are another way to declare delegates with inline code except named
methods.
Restrictions of yield in try-catch.
Posted by: Bhakti | Show/Hide Answer
While using yield keyword, mainly two restrictions are observed.
First is , we can’t use yield in finally.
Second is , we can’t place yield keyword in the catch block if try contains more than one
catch blocks.
With yield break statement, control gets …
Posted by: Bhakti | Show/Hide Answer
NOTE: This is objective type question, Please click question title for correct answer.
What first action compiler will take on detection of iterator ?
Posted by: Bhakti | Show/Hide Answer
As soon as compiler will detect iterator, it will automatically generate current, MoveNext
and Disposemethods of the IEnumerator or IEnumerator(T) type.
What is obsolete method?
Posted by: Virendradugar | Show/Hide Answer
Obsolete means old or no longer in use. We can define a method as obsolete using
Obsolete keyword/attribute.
[Obsolete]
}
or
Sometimes, you may need to not to pass param2. But, optionalParam(1,,3) is not valid
statement with C#. At this point, named parameter comes to the picture.
Example:
int i = 5;
int k= 5;
i == k > True
i.Equals(k) > True
Recommendation :
For value types: use “==”
For reference types: use Equals method.
What is the difference between Parse and TryParse method?
Posted by: Virendradugar | Show/Hide Answer
Parse method is used to parse any value to specified data type.
For example
This will work fine bt what if when you are aware about the value of string variable test.
if test="abc"....
In that case if u try to use above method, .NET will throw an exception as you are trying
to convert string data to integer.
TryParse is a good method if the string you are converting to an interger is not always
numeric.
if(!Int32.TryParse(test,out iResult))
{
//do something
}
The TryParse method returns a boolean to denote whether the conversion has been
successfull or not, and returns the converted value through an out parameter.
So you can declare a local variable of any type using var keyword but you can't declare
an array of variable using var keyword.
Correct
string[] str = { "ram", "sham" };
Wrong
var[] str = { "ram", "sham" };
foreach (var s in str)
This will throw "CS0246: The type or namespace name 'var' could not be found (are you
missing a using directive or an assembly reference?) " error.
Thanks
Is it possible to notify application when item is removed from cache ?
Posted by: Bhakti | Show/Hide Answer
Yes.
You can use CacheItemRemovedCallback delegate defining signature for event handler
to call when item is removed from cache.
For an example:
HttpRuntime.Cache.Insert(
"",
null,
Cache.NoAbsoluteExpiration,
CacheItemPriority.Default,
}
How can you cache Multiple Versions of a Page?
Posted by: Bhakti | Show/Hide Answer
Using output cache you can cache multiple versions of the page.
Programmatic Approach:
Response.Cache.SetCacheability(HttpCacheability.NoCache);
To cache the output for each HTTP request that arrives with a different ID:
Declarative Approach:
<%@ OutputCache duration="60" varybyparam=" ID" %>
Programmatic Approach:
Response.Cache.SetExpires(DateTime.Now.AddSeconds(60));
Response.Cache.SetCacheability(HttpCacheability.Public);
Response.Cache.VaryByParams["ID"] = true;
You have to make user to enter just integer values with TextBox. Can you do this
with CompareValidator?
Posted by: Bhakti | Show/Hide Answer
Yes. With the validator control, you need to set type attribute to the desired datatype
which in this case is “Integer” and Operator to DataTypeCheck.
<asp:CompareValidator ID="CompareValidator1"
ControlToValidate="TextBox1" Type="Integer" Operator="DataTypeCheck"
runat="server"
ErrorMessage="CompareValidator"></asp:CompareValidator>
How to Find Number of Days for provided date range?
Posted by: Bhakti | Show/Hide Answer
Code extract :
To find the difference of the days, here we have used Subtract method. The Subtract
method does not take start date into consideration. Hence, to get the exact number of days
for the date range we need to add one more day to the result.
Thanks
What are three test cases you should do while unit testing?
Posted by: Poster | Show/Hide Answer
Positive test cases
This is done with correct data to check for correct output)
The Runtime Debugger helps tools vendors and application developers find and fix bugs
in programs that target the .NET Framework common language runtime. This tool uses
the runtime Debug API to provide debugging services. Developers can examine the code
to learn how to use the debugging services. Currently, you can only use Cordbg.exe to
debug managed code; there is no support for debugging unmanaged code. To use
CorDbg, you must compile the original C# file using the /debug switch.
Here are some of the main differences between the CLR Debugger and the Visual Studio
Debugger as described in the documentation:
* The CLR Debugger does not support the debugging of Win32 native code applications.
Only applications written and compiled for the common language runtime can be
debugged with the CLR Debugger.
* The Disassembly window is implemented in the CLR Debugger but shows the
disassembly code that would be generated for the application if it were compiled as
Win32 native code rather than common language runtime code. For more information
see, How to: Use the Disassembly Window.
* The CLR Debugger does not support the Autos window feature.
Click for more details http://msdn.microsoft.com/en-us/library/7zxbks7z(VS.80).aspx
Which of the following class does not belong to Collection namespace ?
Posted by: Syedshakeer | Show/Hide Answer
NOTE: This is objective type question, Please click question title for correct answer.
Difference Between String and StringBuilder
Posted by: Majith | Show/Hide Answer
String Class
Once the string object is created, its length and content cannot be modified.
Slower
StringBuilder
Even after object is created, it can be able to modify length and content.
Faster
What will be the output for the following: String str1="Hello"; String str2=str1;
str1=str1+"C#"; Console.WriteLine(str2);
Posted by: Syedshakeer | Show/Hide Answer
NOTE: This is objective type question, Please click question title for correct answer.
What is Microsoft Intermediate Language (MSIL)?
Posted by: Lakhangarg | Show/Hide Answer
A .NET programming language (C#, VB.NET, J# etc.) does not compile into executable
code; instead it compiles into an intermediate code called Microsoft Intermediate
Language (MSIL). As a programmer one need not worry about the syntax of MSIL -
since our source code in automatically converted to MSIL. The MSIL code is then send
to the CLR (Common Language Runtime) that converts the code to machine language,
which is, then run on the host machine. MSIL is similar to Java Byte code.
MSIL is the CPU-independent instruction set into which .NET Framework programs are
compiled. It contains instructions for loading, storing, initializing, and calling methods on
objects.
Combined with metadata and the common type system, MSIL allows for true cross-
language integration Prior to execution, MSIL is converted to machine code. It is not
interpreted.
In C# int Refer to?
Posted by: Lakhangarg | Show/Hide Answer
NOTE: This is objective type question, Please click question title for correct answer.
HashTable Class is present inside which of the following NameSpace?
Posted by: Syedshakeer | Show/Hide Answer
NOTE: This is objective type question, Please click question title for correct answer.
Which of the following is Mutable?
Posted by: Syedshakeer | Show/Hide Answer
NOTE: This is objective type question, Please click question title for correct answer.
Difference between Static and ReadOnly?
Posted by: Syedshakeer | Show/Hide Answer
Static: A variable that retains the same data throughout the execution of a program.
ReadOnly: you can’t change its value.
Which is the Best one for using String concatenation?
Posted by: Syedshakeer | Show/Hide Answer
NOTE: This is objective type question, Please click question title for correct answer.
How can I programmatically list available queues?
Posted by: Pandians | Show/Hide Answer
The GetPublicQueuesByLabel , GetPublicQueuesByCategory , and
GetPublicQueuesByMachine methods of the MessageQueue class provide access to
queues on a network.To specify more exactly the type of queue you are looking for, the
GetPublicQueues method has a MessageQueueCriteria parameter in which you can
specify combinations of search criteria.
What is UDP and how does it work?
Posted by: Pandians | Show/Hide Answer
The User Datagram Protocol (UDP ) provides an unreliable datagram-oriented
protocol on top of IP.The delivery and order of datagrams are not guaranteed.
It is connection-less, that is, a UDP application does not have to connect
explicitly to another. Datagrams are simply sent or received.
How do I call a member method and pass a primitive type (Value Type) by
reference?
Posted by: Pandians | Show/Hide Answer
public bool GetValue( ref int returnValue );
This will pass the numeric by reference.You can modify the value of
returnValue within the body of GetValue and it will persist when the method
call returns.
How to write a method in a class and build as .dll
Posted by: Poster | Show/Hide Answer
To generate a .dll you can following below steps
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
namespace ClassLibrary1
return myName;
There is no need of writing the modifier as by default all methods in the interface is
public.
How to explicitly implement the interface method?
Posted by: Raja | Show/Hide Answer
To explicitly implement interface we need to prefix the method name with the name of
the interface following by .(dot).
string IInterface1.HelloNet()
Arithmetic
+-*/%
String concatenation
+
Increment, decrement
++ --
Shift
<< >>
Relational
== != < > <= >=
Assignment
= += -= *= /= %= &= |= ^= <<= >>=
Member access
.
Indexing
[]
Cast
()
Conditional
?:
Object creation
new
Type information
as is sizeof typeof
Instead of defining an entire class, you can split the definition into multiple classes by
using the partial keyword. When the application is complied, the C# complier will group
all the partial classes together and treat them as a single class. There are a couple of good
reasons to use partial classes. Programmers can work on different parts of a class without
needing to share the same physical file. Also you can separate your application business
logic from the designer-generated code.
C#
{}
{}
}
What is Global Assembly Cache?
Posted by: Raja | Show/Hide Answer
Abbreviated as GAC, the Global Assembly Cache is a machine-wide store used to hold
assemblies that are intended to be shared by several applications on the machine. Each
computer where the common language runtime (CLR) is installed has a global assembly
cache. The global assembly cache stores the assemblies specifically designated to be
shared by several applications on the computer.
C:\>sn -k s.snk
Strong name key is used to specify the strong name used to deploy any application in the
GAC (Global Assembly Catch) in the system.
Class A { static byte a; static short b; static char c; static int d; static long e; static
string s; Public Static Void Main(String args[]) { Console.WriteLine(a+b+c+d+e+s);
}}
Posted by: Syedshakeer | Show/Hide Answer
NOTE: This is objective type question, Please click question title for correct answer.
What is object pooling?
Posted by: Raja | Show/Hide Answer
Object Pooling is something that tries to keep a pool of objects in memory to be re-used
later and hence it will reduce the load of object creation to a great extent.
Object Pool is nothing but a container of objects that are ready for use. Whenever there is
a request for a new object, the pool manager will take the request and it will be served by
allocating an object from the pool.
eg. to create the executable of the .cs file you can use
csc File.cs
IDisposable interface has one public method called Dispose that is used to dispose off the
object. When we use Using statement, we don't need to explicitly dispose the object in
the code, the using statement takes care of it. For eg.
}
When we use above block, internally the code is generated like this
SqlConnection conn = new SqlConnection()
try
finally
Syntax: classname.staticmember
3)'this ' keyword cannot be used inside a static memberfunction
4)Nonstatic members cannot be used inside a static memberfunction
Differrence between Array.CopyTo() and Array.Clone()
Posted by: Syedshakeer | Show/Hide Answer
Both CopyTo() and Clone() make shallow copy (data is copied) and used for Single
Dimension arrays.
Clone() method makes a clone of the original array. It returns an exact length array.
CopyTo() copies the elements from the original array to the destination array starting at
the specified destination array index. Note that, this adds elements to an already existing
array.
In VB.NET, variables has to be declared earlier, before using Clone or CopyTo methods
to store the values. The difference arise on mentioning the size of the array.
While declaring the varaiable that is used for CopyTo method, it should have the size
equal to or more than that of the original array.
While declaring the variable that is used for Clone method we need not mention the array
size. Eventhough the array size is small, it won't show any error, rather the array size gets
altered automatically on cloning. The cloned array size get created equal to the size of the
source array.
If value type is used for CopyTo/Clone any change in the values made on them will not
get reflected on the original whereas on reference type the change gets reflected.
Below is the code which would throw some light on your understanding.
Constructor and Destructor
Posted by: Syedshakeer | Show/Hide Answer
Constructor:
-----------------
1. The Constructor is the first method that is run when an instance of a type is created. In
visual basic a constructor is always Sub new ().
2. Constructor are use to initialize class and structure data before use. Constructor never
returns a value and can be overridden to provide custom initialization functionality.
3. The constructor provides a way to set default values for data or perform other
necessary functions before the object available for use.
Destructor:
---------------
Destructors are called just before an object is destroyed and can be used to run clean-up
code. You can’t control when a destructor is called.
What is extension method in C#?
Posted by: Raja | Show/Hide Answer
Extension method is a new feature in C# 3.0.
Here's a couple of rules to consider when deciding on whether or not to use extension
methods:
For example, if we want to validate an Email address using the static method of the string
class (built-in) class, we can add an extension method like this.
public static bool IsValidEmail(this string input)
return regEx.IsMatch(input);
Notice the parameter passed to above method. Here "this" indicates the string class. Now,
we can use above extension method like this.
For example
In this case a new type will be created on the fly that will have Name, Gender, and Active
as public property and its backing field like _Name, _Gender, _Active.
This is especially useful when we want to receive data from other object or iterate
through a collection and set values and do not want to create a class just to hold the data.
Note that anonymous types are just a placeholder, we can't customize its behavior or add
methods inside it.
What is the use of var keyword in C#?
Posted by: SheoNarayan | Show/Hide Answer
This is the new feature in C# 3.0. This enable us to declare a variable whose type is
implicitly inferred from the expression used to initialize the variable.
eg.
Because the initialization value (10) of the variable age is integer type of age will be
treated as integer type of variable. There are few limitation of the var type of variables.
They are:
OR
A nested class is any class whose declaration occurs within the body of another class or
interface.
An OS process provides isolation by having a distinct memory address space. While this
is effective, it is also expensive, and does not scale to the numbers required for large web
servers. The Common Language Runtime, on the other hand, enforces application
isolation by managing the memory use of code running within the application domain.
This ensures that it does not access memory outside the boundaries of the domain. It is
important to note that only type-safe code can be managed in this way (the runtime
cannot guarantee isolation when unsafe code is loaded in an application domain).
If I want to build a shared assembly, does that require the overhead of signing and
managing key pairs?
Posted by: Rohitshah | Show/Hide Answer
Building a shared assembly does involve working with cryptographic keys. Only the
public key is strictly needed when the assembly is being built. Compilers targeting the
.NET Framework provide command line options (or use custom attributes) for supplying
the public key when building the assembly. It is common to keep a copy of a common
public key in a source database and point build scripts to this key. Before the assembly is
shipped, the assembly must be fully signed with the corresponding private key. This is
done using an SDK tool called SN.exe (Strong Name).
Strong name signing does not involve certificates like Authenticode does. There are no
third party organizations involved, no fees to pay, and no certificate chains. In addition,
the overhead for verifying a strong name is much less than it is for Authenticode.
However, strong names do not make any statements about trusting a particular publisher.
Strong names allow you to ensure that the contents of a given assembly haven't been
tampered with, and that the assembly loaded on your behalf at run time comes from the
same publisher as the one you developed against. But it makes no statement about
whether you can trust the identity of that publisher.
What is the difference between Data Reader & Dataset?
Posted by: Rohitshah | Show/Hide Answer
Data Reader is connected, read only forward only record set.
Dataset is in memory database that can store multiple tables, relations and constraints;
moreover dataset is disconnected and is not aware of the data source.
What is Attribute Programming? What are attributes? Where are they used?
Posted by: Rohitshah | Show/Hide Answer
Attributes are a mechanism for adding metadata, such as compiler instructions and other
data about your data, methods, and classes, to the program itself. Attributes are inserted
into the metadata and are visible through ILDasm and other metadata-reading tools.
Attributes can be used to identify or use the data at runtime execution using .NET
Reflection.
Is String is Value Type or Reference Type in C#?
Posted by: Rohitshah | Show/Hide Answer
String is an object (Reference Type).
An IsolatedStorageFileStream object can be used like any other FileStream object?
Posted by: Raja | Show/Hide Answer
NOTE: This is objective type question, Please click question title for correct answer.
What methods can not be used to create a new isolatedStorageFile object?
Posted by: Raja | Show/Hide Answer
NOTE: This is objective type question, Please click question title for correct answer.
What types of data can a GZipStream compress?
Posted by: Raja | Show/Hide Answer
NOTE: This is objective type question, Please click question title for correct answer.
Which of the following create a FileStream for writing when you want to open an
existing file or create a new one if it doesn’t exist?
Posted by: Raja | Show/Hide Answer
NOTE: This is objective type question, Please click question title for correct answer.
How do you not force changes in a StreamWriter to be sent to the stream it is
writing to?
Posted by: Raja | Show/Hide Answer
NOTE: This is objective type question, Please click question title for correct answer.
Which methods of the FileStream class doesn't affect the Position property?
Posted by: Raja | Show/Hide Answer
NOTE: This is objective type question, Please click question title for correct answer.
Which of the following are types of changes that can be detected by the File-
SystemWatcher?
Posted by: Raja | Show/Hide Answer
NOTE: This is objective type question, Please click question title for correct answer.
Which are NOT acceptable ways to open a file for writing?
Posted by: Raja | Show/Hide Answer
NOTE: This is objective type question, Please click question title for correct answer.
With strict conversions enabled, which of the following would allow an implicit
conversion?
Posted by: Raja | Show/Hide Answer
NOTE: This is objective type question, Please click question title for correct answer.
If there is no valid conversion between two types, what should you do when
implementing the IConvertible interface?
Posted by: Raja | Show/Hide Answer
NOTE: This is objective type question, Please click question title for correct answer.
Structures inherit ToString from System.Object. Why would someone override that
method within a structure?
Posted by: Raja | Show/Hide Answer
NOTE: This is objective type question, Please click question title for correct answer.
Why should boxing be avoided?
Posted by: Raja | Show/Hide Answer
NOTE: This is objective type question, Please click question title for correct answer.
You are creating a generic class, and you need to dispose of the generic objects. How
can you do this?
Posted by: Raja | Show/Hide Answer
NOTE: This is objective type question, Please click question title for correct answer.
Which of the following are not examples of built-in generic types?
Posted by: Raja | Show/Hide Answer
NOTE: This is objective type question, Please click question title for correct answer.
Which of the following statements are false?
Posted by: Raja | Show/Hide Answer
NOTE: This is objective type question, Please click question title for correct answer.
When should you use the StringBuilder class instead of the String class?
Posted by: Raja | Show/Hide Answer
NOTE: This is objective type question, Please click question title for correct answer.
Why should you close and dispose of resources in a Finally block instead of a Catch
block?
Posted by: Raja | Show/Hide Answer
NOTE: This is objective type question, Please click question title for correct answer.
What is the correct order for Catch clauses when handling different exception
types?
Posted by: Raja | Show/Hide Answer
NOTE: This is objective type question, Please click question title for correct answer.
You need to create a simple class or structure that contains only value types. You
must create the class or structure so that it runs as efficiently as possible. You must
be able to pass the class or structure to a procedure without concern that the
procedure will modify it. Which of the following should you create?
Posted by: Raja | Show/Hide Answer
NOTE: This is objective type question, Please click question title for correct answer.
Which of the following is NOT Value type variable?
Posted by: Raja | Show/Hide Answer
NOTE: This is objective type question, Please click question title for correct answer.
You pass a value-type variable into a procedure as an argument. The procedure
changes the variable; however, when the procedure returns, the variable has not
changed. What happened? (Choose one.)
Posted by: Raja | Show/Hide Answer
NOTE: This is objective type question, Please click question title for correct answer.
What is the best way to add items from an Array into ArrayList?
Posted by: Raja | Show/Hide Answer
Use AddRange method of the ArrayList.
arrList.AddRange(arr);
Write a single line of code to create a text file and write contents into it.
Posted by: Raja | Show/Hide Answer
Use following code
System.IO.File.WriteAllText(@"c:\MyTextFile.txt", "MyContents");
Write a single line of code to read the entire content of the text file.
Posted by: Raja | Show/Hide Answer
User following code
Console.WriteLine("{0:x2}", myStream.ReadByte());
}
How to sort an array into descending order?
Posted by: Raja | Show/Hide Answer
First sort the array using Array.Sort and then use Array.Reverse
Eg.
}
How to convert a sentence into Title Case (Capitalize first character of every word)?
Posted by: Raja | Show/Hide Answer
Use ToTitleCase method.
System.Globalization.CultureInfo.CurrentCulture.TextInfo.ToTitleCase(&q
uot;dotnetfunda.com is a very good website");
When we instantiate a class, memory will be allocated on the heap and when struct gets
initiated it gets memory on the stack.
Classes can have explicit parameter less constructors. But structs dosn't have this.
A struct cannot inherit from another struct or class, and it cannot be the base of a class.
Like classes, structures can implement interfaces.
How to load assembly from GAC?
Posted by: SheoNarayan | Show/Hide Answer
Lets say you have to load the assembly from GAC on button click event then you should
write following method.
Assembly al = Assembly.Load(asm);
Type t = al.GetType("ClassLibrary1.Class1");
MethodInfo m = t.GetMethod("Method1");
MessageBox.Show(str);
For eg:
<object>.Dispose.
Finalize is used to fire when the object is going to realize the memory.We can set a alert
message to says that this object is going to dispose.
How to declare methods into an Interface
Posted by: SheoNarayan | Show/Hide Answer
void Calculate();
int Insert(string firstName, string lastName, int age);
OR
Reflection is the ability to find out information about objects, the application details
(assemblies), its metadata at run-time.
Edited:
See the example: http://www.dotnetfunda.com/articles/article132.aspx
What is Delegates?
Posted by: Raja | Show/Hide Answer
A delegate in C# allows you to pass method of one class to objects of other class that can
call these methods.
OR
reader = cmd.ExecuteReader(CommandBehavior.CloseConnection);
This will make sure that when we are calling reader.Close() the associated connection
object will also be closed.
What are the different ways a method can be overloaded?
Posted by: Raja | Show/Hide Answer
Different parameter data types, different number of parameters, different order of
parameters.
Can you allow a class to be inherited, but prevent the method from being over-
ridden?
Posted by: Raja | Show/Hide Answer
Yes. Just leave the class public and make the method sealed.
Can you prevent your class from being inherited by another class?
Posted by: Raja | Show/Hide Answer
Yes. The keyword “sealed” will prevent the class from being inherited.
What class is underneath the SortedList class?
Posted by: Poster | Show/Hide Answer
A sorted HashTable.
How can you sort the elements of the array in descending order?
Posted by: Poster | Show/Hide Answer
By calling Array.Sort() and then Array.Reverse() methods.
What’s the difference between the System.Array.CopyTo() and
System.Array.Clone()?
Posted by: Poster | Show/Hide Answer
The Clone() method returns a new array (a shallow copy) object containing all the
elements in the original array. The CopyTo() method copies the elements into another
existing array. Both perform a shallow copy. A shallow copy means the contents (each
array element) contains references to the same object as the elements in the original
array. A deep copy (which neither of these methods performs) would create a new
instance of each element's object, resulting in a different, yet identacle object.
Are private class-level variables inherited?
Posted by: Poster | Show/Hide Answer
Yes, but they are not accessible. Although they are not visible or accessible via the class
interface, they are inherited.
How is the DLL Hell problem solved in .NET?
Posted by: Poster | Show/Hide Answer
Assembly versioning allows the application to specify not only the library it needs to run
(which was available under Win32), but also the version of the assembly.
What is a collection?
Posted by: Poster | Show/Hide Answer
A collection serves as a container for instances of other classes. All classes implement
ICollection interface which intern implement IEnumerable interface.
What is the use of Monitor in C#?
Posted by: Raja | Show/Hide Answer
It provides a mechanism that synchronizes access to objects.
The Monitor class controls access to objects by granting a lock for an object to a single
thread. Object locks provide the ability to restrict access to a block of code, commonly
called a critical section. While a thread owns the lock for an object, no other thread can
acquire that lock. You can also use Monitor to ensure that no other thread is allowed to
access a section of application code being executed by the lock owner, unless the other
thread is executing the code using a different locked object.
ForEach loop
foreach (DataRow row in dTable.Rows)
yourvariable = row["ColumnName"].ToString();
For loop
for (int j = 0; j< dTable.Rows.Count; j++)
{
yourvariable = dTable.Rows[j]["ColumnName"].ToString()l
}
What is lock statement in C#?
Posted by: Raja | Show/Hide Answer
Lock ensures that one thread does not enter a critical section of code while another thread
is in the critical section. If another thread attempts to enter a locked code, it will wait,
block, until the object is released.
Is overriding of a function possible in the same class?
Posted by: Poster | Show/Hide Answer
NOTE: This is objective type question, Please click question title for correct answer.
What is static constructor?
Posted by: Raja | Show/Hide Answer
Static constructor is used to initialize static data members as soon as the class is
referenced first time, whereas an instance constructor is used to create an instance of that
class with keyword. A static constructor does not take access modifiers or have
parameters and can't access any non-static data member of a class.
What is Stack?
Posted by: Raja | Show/Hide Answer
This is a collection that abstracts LIFO (Last In First Out) data structure in which initial
capacity is 32.
What is Queue?
Posted by: Raja | Show/Hide Answer
This is a collection that abstracts FIFO (First In First Out) data structure. The initial
capacity is 32 elements. It is ideal for messaging components.
What is an ArrayList?
Posted by: Raja | Show/Hide Answer
ArrayList is a dynamic array. Elements can be added & removed from an arraylist at the
runtime. In this elements are not automatically sorted.
What is an Array?
Posted by: Raja | Show/Hide Answer
An array is a collection of related instance either value or reference types. Array posses
an immutable structure in which the number of dimensions and size of the array are fixed
at instantiation.
Single Dimensional Array: it is sometimes called vector array consists of single row.
Jagged Array: also consists of rows & columns but in irregular shaped (like row 1 has 3
column and row 2 has 5 column)