C#
C#
Unit – I –INTRODUCTION TO C#
C# complies straight from source code to executable code, with no object files.
In c++, class definition does not use a semicolon at the end
C# does not support #include statement
In c#, switch can also be used on string values.
1
It has a lean and consistent syntax.
5. What is .net?
.net is the software framework that includes everything required for
developing software for web services.
The code that satisfies the CLR at runtime in order to execute is referred to as
managed code. For example c# complier generates II, code(managed code).
C# includes a feature that enables us to define more than one class with the main
method. Since main is the entry point for program execution there are now than one entry
points. In facts there should be only one. This problem can be resolved by specifying
which main is to be used to the complier at the time of compilation as shown below;Csc
filename.cs/main: classname
Variable declared inside methods are called local variables. Local variable can
also be declared inside program blocks that are defined between an opening brace {and
the closing brace}. The scope of a local variable starts after immediately after its
identifier in the declaration and extends up to the end of the block containing the
declaration.
A variable must be given a value after it has been declared but before it is used in
an expression. A simple method of giving value to a variable is through the assignment
statement as follow,Variable name=value;
byte b1 = 50;
byte b2 = 60;
byte b3 = b1 + b2;
2
11. What do you mean by implicit conversion?
It can always be performed without any loss of data. For numeric types, this
implies that the destination type can be fully representing the range of the sources type.
For example, a short can be converted implicitly to an int, because the shott range is a
subset of the int range.
Therefore,
Short b= 75;
There are many conversions that cannot be implicitly made between types. If we
attempt such conversions, the complier will give an error message.
Value parameters are used for passing parameters into methods by value. The
parameters are declared with no modifier is passed by value and is called a value
parameters.
In c#, we can define methods that can handle variable numbers of arguments
using what are known as parameters arrays. Parameters arrays are declared using the
keyword params.
Example:
……….
……….
3
15. What is a variable size array?
String objects are immutable, meaning that we cannot modify the characters
contained in them.
We are assigning the modified value to a new string variable. For instance, s1 = s1
.insert (3, “r”);
Is illegal .we are trying to modify the immutable string object s1.
4
18. What is the purpose of a constructor in a structure?
The constructor is a method which is used to set values of data members at the
time of declaration. The constructor method has the same name as struct and declared as
public. The constructor is invoked as follows:
This statement creates a struct object nl and assigns the value 100 to its only data
members number.
The methods may be designed to perform certain operation on the data stored in
struct objects. note that a struct is not permitted to declare a destructor.
The output parameter are used to pass result backs to the calling method. This is
achieved by declaring parameters with an out keyword. An output parameter does not
create a new location.
5
UNIT-2- OBJECT ORIENTED ASPECTS TO C#
1. What is a constructor?
A constructor initializes an object when it is created. It has the same name as its
class and is syntactically similar to a method. However, constructor have no explicit
return type. The general form of constructor if shown here:
Access class-name()
//constructor code
A static constructor is called before any object of the class is created. This is
useful to do any housekeeping work that needs to be done once. it is usually used to
assign initial values to static data members.
4. What is property?
Another type of class members is the property. A property combines a field with
the methods that access it. if you want to create a field that is available to users of an
objects, but you want to maintain control over the operations allowed on that field.
There are situations where we would like to decide the value of a constant
member at run-time. We may also like to have different constant values for different
objects of the class. To overcome these shortcomings, c# provides another modifier
known as read only
6. What is an indexer?
6
7. What are the two form of inheritance?
We can use the modifier new to tell the compiler that the derived class method
“hides” the base class method.
9. What is polymorphism?
Operation Polymorphism
Inclusion Polymorphism
The compiler is able to select and bind the appropriate method to the object for a
particular call at complier time itself. this process is called early binding, or static binding
,it is also known as complier time polymorphism
The decision on exactly which method to call is delayed until runtime and,
therefore, it is also known as runtime polymorphism. Since the method is linking with a
particular class much later after compilation, this process is termed late binding.
This means, c# has the ability to provide the operator with a special meaning for
data type.this mechanism of giving such special meaning to an operator is known as
operator overloading.
Category Operations
Binary arithmetic +,*,?,-,%
Unary arithmetic +,-,++,--
Binary bitwise &,|,^,<<,>>
Unary bitwise !,~,true, false
7
14. List the operators that cannot be overloaded?
Category Operations
Conditional operators &&,||
Compound assignment +=,-=,*=,/=,%=
Delegate declaration
Delegate methods definition
Delegate instantiation
Delegate invocation
16. What delegate method?
It is possible for certain delete to hold and invoke multiple methods. Such
delegate are called multicast delegates. Multicast delegates, also known as
combinable delegates, must satisfy the following conditions:
None of the parameter of the delegate type can be declared as out put
parameter, using out keyword.
An event is a delegate type class member that is used by the objects or class to
provide a notification to other objects that event has occurred. The client object can act on
an event by adding an event handler to the event
An interface can contain one or more methods, properties, indexers and events but
none of them are implemented in the interface itself. It is the responsibility of the class
that implements to define the code for implementation of theses members.
8
20. What is the purpose of using the finally block?
9
UNIT-III- APPLICATION DEVELOPMENT ON .NET
1. List out the different types of applications that can be created on .net?
.Net offers closely related but distinguishable suites of tools for building windows
or web applications. Both are based on the premises that many application have user
interfaces centered on interacting with the user through form and controls, such as
buttons, list boxes, text, and so forth.
Secondly, you can’t delete a customer record it that customerID is used in any
order. The integrity of your data and its relationship is thus protected.
10
6. Define Data Adapter?
First open visual studio and file ----->new- - - -> project.In project window, create
a new c# windows application and name itsharpwindowsform.
The actually uses a data reader to populate itself. A data reader is lean, mean
access Methods that return results as soon as they are available, rather than for the whole
of the query to be populated into a dataset.
Now that you can check the files and pick the target directory,you are ready to
handle the copy button-click event.The very first thing you need to do is to get a list of
which files were selected .
11
13. Define normalization.
Normalization not only makes your use of the database more efficient,but also it
reduces the likelihood of data corruption.if you kept the customer’s name in both the
customer table and the order table,you would run the risk that a change in one table might
not be reflected in the order table.by keeping only the customerID in order,you are free to
chage the address in customers,and the change is automatically reflected for each order.
The most popular language for querying and manipulating database is SQL,
usually pronounced “Sequel”.SQL is a declarative language,as opposed to a procedural
language.the heart of SQL is query.query is statement that return a set of record from the
database.
The DBCommand object allows you to send a command to the database.often these
objects are implicitly create when you create a dataadapter, but you can explicitly access
these object.
The DBConnection objects represent a connection to data source. This connection can
be shared among different command object.
The data table has a number of public properties, including the columns
connection, which returns the data columns connection object .each data column object
represent a column in a table.
Data table’s rows collection returns a set of rows for that table. use this collection
to examine the results of queries against the database, iterating through the rows to
examine each record in turn.
12
20. What are the advantages of ADO.NET model?
Highly efficient, but to be effective the dataset must be a robust subset of the
database, capturing not just a few rows from a single table, but also a set of tables with
all metadata necessary to represent the relationship and constraints of the original
database.
13
UNIT IV- WEB BASED APPLICATION DEVELOPMENT ON .NET
.NET wants you to use server side controls that can often generate unnecessary
trips back to the server by default. Plus, .NET also want to make the determination as to
how will acts with various browsers. While not impossible, it is make it much more
cumbersome to create custom workaround for special situations. Not to mention the
facts that new browsers are released in between .NET services pack updates.
2. List out the server side state management options supported by ASP.NET.
Application states
Session states
Profile properties
Database Support
3. Differentiate the postback events with nonpostback events?
Post back events are those that cause the form to be posted back to the server
immediately.
In contrast, many event are considered nonpostback in that the form isn’t posted
back it the server immediately. Instead these events are cached by the control until the
next time a post back event occurs.
4. What is WSDL?
A lot of work is being done for you automatically. HTML pages describing
your web services and its methods are generated and this page includes links to pages
in which the methods can be tested.
Initialize, load view state, process postback data, load, handle postback events,
prerender, save state, render, dispose
This is your last chance to modify the output the output prior to rendering
using the OnPreRender () method.
14
7. Define Client-side support?
You make use of a web service by writing client code that acts as though it
were communicating directly with a local object, but in reality communicates with
host server through a proxy.
While creating a web service requires no special programming on your part, you
need only write the implementing code, add the [web method] attribute and let the server do
rest.
9. What is SOAP?
The life cycle begins with request for the page, which cause the server to load it.
When the request is complete, the page is unloading.
.Net web services help you write components whose methods can be invoked
across the internet using any .Net programming language.
To create the proxy, enter wsdl at the visual studio command-line prompt, followed
by the path to the wsdl contract. For example
Wsdl http://localhost:19975/calculatorws/service.asmx?wsdl
15
15. Define Load View state.
The view state property of the control is populated. The view state information
comes from hidden variable on the control, used to persist the state across round trip to
server.
This is where the output to be sent back to the client browser is generated. You
can overwrite it using render method.
This is the last phase of the life cycle. It gives you an opportunity to do any final
cleanup and release reference to any expensive recourse, such as data base connection.
During the phase, the data sent to the server in the posting is processed. if any of
this data results in a requirement to update the viewstate, that update is performed via
the loadpostdata()method.
16
UNIT V-CLR AND .NET FRAMEWORK
With a well-known singleton object, all messages for the object, from all clients,
are dispatched to a single objet running on the server.
With a well-known single-call object, each new message from a client is handling
by a new objects.
3. Define metadata?
Assemblies are the .NET unit of reuse, versioning, security, and deployment. In
addition to the objects code for the application, assemblies contain resources.
4. What is PF files.
On disk, assemblies are portable executable files, PF files are not new. The format
of a.NET PE file is exactly the same as a normal windows PE files. PE files are
implemented as DLLS or EXEs.it consist of one or more modules.
If you want to share your assembly, it must meet certain stringent requirement
Your assembly must have a strong name. strong name are globally unique.
To share your assembly place it in the global assembly cach .this is an area of the
file system set aside by the CLR to hold shared assemblies.
17
Private and shared. Private assemblies are intended to be used by only one
application. Shared assemblies are intended to be shared among many applications.
8. Define attributes
Attributes are a mechanism for adding metadata ,such as compiler instructions and
other data about your data , method, and classes to the program itself. Attributes are
inserted into the metadata and are visible through ILDasam and other metadata-reading
tools.
9. Define reflection
Reflection is the process by which a program can read its own metadata or
metadata from another program. A program is said to reflect on itself or on another
program, extracting metadata from the reflected assembly and using that metadata either
to inform the user or to modify the program’s behavior
.NET want you to use server side controls that can often generate unnecessary
trips back to the server by default.plus .NET also wants to make the determination as to
how the control will act with various browsers.while not impossible,it makes it much
more cumbersome to create custom workarounds for special situation.
12. List out the server side state management option suppoted by asp.net?
Application state
Session state
Profile properties
Database support
When you tell a thread to stop processing and wait until a second thread Complete
its work, you are said to be joining the first thread to the second.
18
The simplest way to create a thread is to create a new instance of the Thread class.
The thread constructor takes a single argument.
App domain can be independently started and halted. They are secure, lightweight
and versatile. An app domain can provide fault tolerance. If you start an object in a
second app domain and it crashes.
18. What are the methods and properties of the app domain class.
CurrentDomain
createDomain()
GetcurrentthreadID()
Unload ()
FriendlyName GetData ()
Load ()
setData()
19. Define Member Filter?
A delegate that filter the list of members in the member info array of object. You
use a type.filtername filter, which is a field of the type class that filter on the name.
Viewing metadata
Performing type discovery
Late binding to method and properties
Creating types at runtime (reflection emit)
19