Nothing Special   »   [go: up one dir, main page]

Question Paper of UNIT-IV

Download as pdf or txt
Download as pdf or txt
You are on page 1of 6

Department of CSE, AITS Haldawani

Question Paper of UNIT-IV

Class: B.Tech. (CSE) VII Semester

Subject: .Net Framework and C# Programming (BCST-701)

Q1. What is Streem in C#?


Ans: The stream is basically the sequence of bytes passing through the communication path.
There are two main streams: the input stream and the output stream. The input stream is used for
reading data from file (read operation) and the output stream is used for writing into the file
(write operation).

Q2. What is I/O Class? Describe some important various classes.


Ans: The System.IO namespace has various classes that are used for performing numerous
operations with files, such as creating and deleting files, reading from or writing to a file, closing
a file etc.

I/O Class Description

BinaryReader Reads primitive data from a binary stream.

BinaryWriter Writes primitive data in binary format.

BufferedStream A temporary storage for a stream of bytes.

Directory Helps in manipulating a directory structure.


DriveInfo Provides information for the drives.

File Helps in manipulating files.

FileInfo Used for performing operations on files.

FileStream Used to read from and write to any location in a file.

MemoryStream Used for random access to streamed data stored in


memory.

Path Performs operations on path information.

StreamReader Used for reading characters from a byte stream.

StreamWriter Is used for writing characters to a stream.

StringReade Is used for reading from a string buffer.

StringWriter Is used for writing into a string buffer.

Q3. Write syntax to creating file stream.


Ans:
The syntax for creating a FileStream object is as follows. object F for reading a file
named sample.txt
FileStream F = new FileStream("sample.txt", FileMode.Open, FileAccess.Read,
FileShare.Read);
Q4. Write the syntax of the following method to read data from file.
a) Read all text
b) Read all line
Ans:
The following list describes some of these methods:
a) The "ReadAllText" method reads the data of a file.
string filePath = @"C:\MyData\TestFile.txt";
string testData = File.ReadAllText(filePath);

b) The "ReadAllLines" method reads all the contents of a file and stores each line at a new
index in an array of string type.
string filePath = @"C:\MyData\TestFile.txt";
string[] testDataLineByLine = File.ReadAllLines(filePath);

Q5. Write a program in C# to write and read a file.


Ans:

OUTPUT:
Q6. What is Binary writer class? Describe with example.
Ans:
The BinaryWriter class provides methods that simplify writing primitive data types to a stream.
For example, you can use the Write method to write a Boolean value to the stream as a one-byte
value. The class includes write methods that support different data types.

Q7. What is serialization in C#?


Ans:
Serialization is the process of converting object into byte stream so that it can be saved to
memory, file or database. The reverse process of serialization is called deserialization.
Serialization is internally used in remote applications.
Q8. What is Remoting? Describe the Components communicate directly across an
application domain boundary.
Ans:
.NET remoting framework provides an approach to interprocess communication that abstracts
the remotable object from a specific client or server application domain and from a specific
mechanism of communication.

To use .NET remoting to build an application in which two components communicate directly
across an application domain boundary, the following components are required:

• A remotable object, which is referred to as ServerObject in the typical architecture of a


distributed application diagram.
• A host application domain to listen for requests for that object (Application Domain 2 in
the typical architecture of a distributed application diagram).
• A client application domain that makes requests for that object (Application Domain 1 in
the typical architecture of a distributed application diagram).

Q9. What is ADO .NET? Describe the component of ADO .NET.


Ans:
ADO stands for Microsoft ActiveX Data Objects. ADO.NET is one of Microsoft’s Data Access
technology using which we can communicate with different data sources. It is a part of the .Net
Framework which is used to establish a connection between the .NET Application and data
sources. The Data sources can be SQL Server, Oracle, MySQL, and XML, etc. ADO.NET
consists of a set of classes that can be used to connect, retrieve, insert, update and delete data (i.e.
performing CRUD operation) from data sources. ADO.NET mainly
uses System.Data.dll and System.Xml.dll.
Components are designed for data manipulation and faster data access. Connection, Command,
DataReader, DataAdapter, DataSet, and DataView are the components of ADO.NET that are
used to perform database operations. ADO.NET has two main components that are used for
accessing and manipulating data. They are as follows:
➢ Data provider (retrieve data or to do some insert, update, and delete operations from or
to a database)
➢ DataSet. (DataSet contains a collection of one or more DataTable objects)
Q10. Write syntax in C# to connect a Database.
Ans:

1. using System;
2. using System.Data.SqlClient;
3. namespace AdoNetConsoleApplication
4. {
5. class Program
6. {
7. static void Main(string[] args)
8. {
9. new Program().Connecting();
10. }
11. public void Connecting()
12. {
13. using (
14. // Creating Connection
15. SqlConnection con = new SqlConnection("data source=.; database=student; in
tegrated security=SSPI")
16. )
17. {
18. con.Open();
19. Console.WriteLine("Connection Established Successfully");
20. }
21. } } }

You might also like