Technical Test Paper 2
(File system,collection,Generic,Treading)
Q . 1) In which collection is the Input / Output based on key?
Ans:- HashTable
SortedList
Q. 2)In a HashTable key can not be NULL,but Value can be.
Ans:- True
Q. 3) Which of The following statements are correct about the C#.NET code snippet given ?
Stack s=new Stack();
s.Push("Hello");
s.Push(8.2);
s.Push(5);
s.Push('b');
s.Push(true);
Ans:- HashTable
SortedList
Q. 2)In a HashTable key can not be NULL,but Value can be.
Ans:- True
Q. 3) Which of The following statements are correct about the C#.NET code snippet given ?
Stack s=new Stack();
s.Push("Hello");
s.Push(8.2);
s.Push(5);
s.Push('b');
s.Push(true);
Ans:- This is perfectly workable code.
Q. 4) A HashTable t maintains a collection of names of states and capital city of each state.Which is correct way to find out
wheatther " Kerla '' state is present in this collection or not?
Ans:- t.ContainsKey("Kerla");
Q. 5) Suppose value of the Capacity
property of ArrayList Collection is set to 4.What will be the capacity
of the collection on adding fifth element to it?
Ans:- 8
Q. 6) Which of the following statement are correct about Collection Classes available in network class library
Ans:-They use efficient algorithms to manage the collection,thereby improving the performance of the program.
Q. 7) What is advantages of generics?
Ans:- Generic Provide type safety without the overhead of multiple imlementation.
Q.8) Which are the classes are present in system.Collection.Generic namespaces?
Ans:- Stack
SortedDictionary
Q. 9) Trace the output
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
namespace ConsoleApplication4
{
class Program
{
public static void CallToChildThread()
{
Console.WriteLine(" child thread starts");
int sleepfor = 5000;
Console.WriteLine("Child thread paused for {0} seconds",sleepfor/1000);
Thread.Sleep(5000);
Console.WriteLine("child thread resumes");
}
static void Main(String[] args)
{
ThreadStart childref = new ThreadStart(CallToChildThread );
Console.WriteLine("In main: creating the child thread");
Thread childthread = new Thread(childref );
childthread.Start();
Console.ReadKey();
}
}
}
Ans:-o/p:-
In main: creating the child thread
child thread starts
Child thread paused for 5 seconds
child thread resumes
Ans:- 8
Q. 6) Which of the following statement are correct about Collection Classes available in network class library
Ans:-They use efficient algorithms to manage the collection,thereby improving the performance of the program.
Q. 7) What is advantages of generics?
Ans:- Generic Provide type safety without the overhead of multiple imlementation.
Q.8) Which are the classes are present in system.Collection.Generic namespaces?
Ans:- Stack
SortedDictionary
Q. 9) Trace the output
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
namespace ConsoleApplication4
{
class Program
{
public static void CallToChildThread()
{
Console.WriteLine(" child thread starts");
int sleepfor = 5000;
Console.WriteLine("Child thread paused for {0} seconds",sleepfor/1000);
Thread.Sleep(5000);
Console.WriteLine("child thread resumes");
}
static void Main(String[] args)
{
ThreadStart childref = new ThreadStart(CallToChildThread );
Console.WriteLine("In main: creating the child thread");
Thread childthread = new Thread(childref );
childthread.Start();
Console.ReadKey();
}
}
}
Ans:-o/p:-
In main: creating the child thread
child thread starts
Child thread paused for 5 seconds
child thread resumes
Q.10) Explain Thread LifeCycle .
Ans:------
A thread is
defined as the execution path of a program. Each thread defines a
unique flow of control. If your application involves complicated and
time consuming operations then it is often helpful to set different
execution paths or threads, with each thread performing a particular
job.
Ans:------
Threads are lightweight processes.
One common example of use of thread is implementation of concurrent
programming by modern operating systems. Use of threads saves wastage of
CPU cycle and increase efficiency of an application.
So
far we have written programs where a single thread runs as a single
process which is the running instance of the application. However, this
way the application can perform one job at a time. To make it execute
more than one task at a time, it could be divided into smaller threads.
The
life cycle of a thread starts when an object of the
System.Threading.Thread class is created and ends when the thread is
terminated or completes execution.
11. Discuss File System in Detail.
ANS :
FileStream typical use
This is typical code when opening file using FileStream. It's important to always close the stream. If you don't close the stream it can take a minute to be file again accessible (it will wait to garbage collector to free the FileStream instance and close the file).
[C#] Open existing file for read and write.
FileStream fileStream = new FileStream(@"c:\file.txt", FileMode.Open);
[C#] Open existing file for reading.
FileStream fileStream = new FileStream(@"c:\file.txt", FileMode.Open, FileAccess.Read);
[C#] Open existing file for writing.
FileStream fileStream = new FileStream(@"c:\file.txt", FileMode.Open, FileAccess.Write);
[C#] Open file for writing (with seek to end), if the file doesn't exist create it.
FileStream fileStream = new FileStream(@"c:\file.txt", FileMode.Append);
[C#] Create new file and open it for read and write, if the file exists overwrite it.
FileStream fileStream = new FileStream(@"c:\file.txt", FileMode.Create);
[C#] Create new file and open it for read and write, if the file exists throw exception.
FileStream fileStream = new FileStream(@"c:\file.txt", FileMode.CreateNew);
Example;
Following are the various states in the life cycle of a thread:
- The Unstarted State: it is the situation when the instance of the thread is created but the Start method has not been called.
- The Ready State: it is the situation when the thread is ready to run and waiting CPU cycle.
- The Not Runnable State: a thread is not runnable, when:
- Sleep method has been called
- Wait method has been called
- Blocked by I/O operations
- The Dead State: it is the situation when the thread has completed execution or has been aborted.
11. Discuss File System in Detail.
ANS :
FileStream typical use
This is typical code when opening file using FileStream. It's important to always close the stream. If you don't close the stream it can take a minute to be file again accessible (it will wait to garbage collector to free the FileStream instance and close the file).
[C#] Open existing file for read and write.
FileStream fileStream = new FileStream(@"c:\file.txt", FileMode.Open);
[C#] Open existing file for reading.
FileStream fileStream = new FileStream(@"c:\file.txt", FileMode.Open, FileAccess.Read);
[C#] Open existing file for writing.
FileStream fileStream = new FileStream(@"c:\file.txt", FileMode.Open, FileAccess.Write);
[C#] Open file for writing (with seek to end), if the file doesn't exist create it.
FileStream fileStream = new FileStream(@"c:\file.txt", FileMode.Append);
[C#] Create new file and open it for read and write, if the file exists overwrite it.
FileStream fileStream = new FileStream(@"c:\file.txt", FileMode.Create);
[C#] Create new file and open it for read and write, if the file exists throw exception.
FileStream fileStream = new FileStream(@"c:\file.txt", FileMode.CreateNew);
Example;
using System;
using System.IO;
class Test
{
public static void Main()
{
string path = @"c:\temp\MyTest.txt";
if (!File.Exists(path))
{
// Create a file to write to.
using (StreamWriter sw = File.CreateText(path))
{
sw.WriteLine("Hello");
sw.WriteLine("And");
sw.WriteLine("Welcome");
}
}
// Open the file to read from.
using (StreamReader sr = File.OpenText(path))
{
string s = "";
while ((s = sr.ReadLine()) != null)
{
Console.WriteLine(s);
}
}
}
}
using System.IO;
class Test
{
public static void Main()
{
string path = @"c:\temp\MyTest.txt";
if (!File.Exists(path))
{
// Create a file to write to.
using (StreamWriter sw = File.CreateText(path))
{
sw.WriteLine("Hello");
sw.WriteLine("And");
sw.WriteLine("Welcome");
}
}
// Open the file to read from.
using (StreamReader sr = File.OpenText(path))
{
string s = "";
while ((s = sr.ReadLine()) != null)
{
Console.WriteLine(s);
}
}
}
}
No comments:
Post a Comment