1. Which of the following define the rules for .NET Languages?
Answers:
Answers:
List<Person> people = PopulateList();
What does the statement below do?
people.Sort((x, y) => string.Compare(x.LastName, y.LastName));
Answers:
Answers:
Answers:
Answers:
class Test
{
static void Main() {
string myString = “1 2 3 4 5”
myString = Regex.Replace(myString, @”s+”, ” “);
System.Console.WriteLine(myString);
}
Answers:
Answers:
public static byte[] ReadFully(Stream input)
{
using (MemoryStream ms = new MemoryStream())
{
input.CopyTo(ms);
return ms.ToArray();
}
}
Answers:
Answers:
Answers:
Answers:
Answers:
Answers:
List<Employee> lstEmployees = new List<Employee>
{
new Employee{Name=”Harry”,Age=15},
new Employee{Name=”Peter”,Age=22},
new Employee{Name=”John”,Age=45},
new Employee{Name=”Harry”,Age=15},
new Employee{Name=”Peter”,Age=22},
new Employee{Name=”John”,Age=45},
};
It is required to filter out employees having distinct names.
Which one of the following options cannot be used?
Answers:
Answers:
static void Main(string[] args)
{
int @int = 15;
Console.WriteLine(@int);
Console.ReadLine();
}
Answers:
try {
// Code that might throw exceptions of different types
}
catch {
// Code goes here
}
Answers:
Answers:
string[] lines = theText.Split(new string[] { Environment.NewLine }, StringSplitOptions.None);
Answers:
string s1 = “Old Value”;
string s2 = s1;
s1 = “New Value”;
Console.WriteLine(s2);
What will be the output printed, and why?
Answers:
private void Form1_Load(object sender, EventArgs e)
{
try
{
ThreadPool.QueueUserWorkItem(ShowMessage,null);
}
catch (Exception ex)
{
}
}
private void ShowMessage(object obj)
{
try
{
lblMessage.Text = “Hello from Thread Pool”;
}
catch (Exception ex)
{
}
}
Answers:
Answers:
Answers:
“ttttt”
Answers:
In C#, exception handling should be used…
Answers:
Answers:
Answers:
Answers:
Answers:
Answers:
class X {
private int i;
protected float f;
public char c;
}
class Y : X { }
Answers:
Answers:
Answers:
public class Person
{
public string GetAge()
{
lock (this)
{
// Code to get Age of this person object.
}
}
}
Which of the following statements is true?
Answers:
Answers:
Answers:
Answers:
A) lock(this.locker) this.counter++;
B) Interlocked.Increment(ref this.counter);
C) Change the access modifier of counter to public volatile
Which statement is incorrect with regards to these approaches?
Answers:
public class var { }
public class main
{
public static void main(string[] args)
{
var testVar = new var();
}
}
Answers:
Answers:
Answers:
Answers:
Answers:
Answers:
[Flags]
public enum Permissions
{
None = 0,
Read = 1,
Write = 2,
Delete = 4
}
What will be the output of the following Main program (which has access to the enum defined above) in this C# console application (Assume required namespaces are included) :
static void Main(string[] args)
{
var permissions = Permissions.Read | Permissions.Write;
if ((permissions & Permissions.Write) == Permissions.Write)
{
Console.WriteLine(“Write”);
}
if ((permissions & Permissions.Delete) == Permissions.Delete)
{
Console.WriteLine(“Delete”);
}
if ((permissions & Permissions.Read) == Permissions.Read)
{
Console.WriteLine(“Read”);
}
Console.ReadLine();
}
Answers:
Answers:
protected internal class A
{
}
Which statement is correct with regards to its accessibility?
Answers:
Answers:
int num1 = 10, num2 = 9;
int result = num1 & num2;
Answers:
class CCheck {
public static void Main() {
string str = @”E:\RIL\test.cs”;
Console.WriteLine(str);
}
}
Answers:
public string GetName(int iValue)
{
string sValue = “0”;
switch (iValue)
{
case 1:
sValue = iValue.ToString();
case 2:
sValue = iValue.ToString();
break;
default:
sValue = “-1”;
break;
}
return sValue;
}
Answers:
static void Main(string[] args)
{
for (int i = 0; i < 1; i++)
{
Console.WriteLine(“No Error”);
}
int A = i;
Console.ReadLine();
}
Answers:
Answers:
public int fn(int var)
{
int retvar = var – (var / 10 * 5);
return retvar;
}
Answers:
Answers:
Answers:
Answers:
Answers:
Answers:
Answers:
Answers:
Answers:
Answers:
Answers:
Answers:
Answers:
Answers:
Answers:
Answers:
Answers:
A:
try {
// code goes here
} catch (Exception e) {
throw e;
}
B:
try {
// code goes here
} catch (Exception e) {
throw;
}
Answers:
Answers:
static void Main(string[] args)
{
string Invalid = “$am$it$”;
string sResult = Invalid.Trim(new char[]{‘$’});
Console.WriteLine(sResult);
Console.ReadLine();
}
Answers:
Answers:
Answers:
1.
catch (Exception exc)
{
throw exc;
}
2.
catch (Exception exc)
{
throw;
}
Answers:
int num1 = 10, num2 = 9;
int result = num1 ^ num2;
Answers:
static void Main(string[] args)
{
string sPrint = String.Format(“{{ My name is bond. }}”);
Console.WriteLine(sPrint);
Console.ReadLine();
}
Answers:
Answers:
Workbooks books = excel.WorkBooks;
Workbook book = books[1];
Sheets sheets = book.WorkSheets;
Worksheet ws = sheets[1];
Answers:
Answers:
Answers:
- GAC
- CLS
- CLI
- CTS
- CLR
- JIT
Answers:
- Assembly.Load(”Kernel32.DLL”)
- LoadLibrary(”Kernel32.DLL”)
- [DllImport(”kernel32”, SetLastError=true)]
- Unmanaged DLLs cannot be used in a managed .NET application.
List<Person> people = PopulateList();
What does the statement below do?
people.Sort((x, y) => string.Compare(x.LastName, y.LastName));
Answers:
- It will return a newly created sorted List.
- It will throw a compiler error.
- It will sort the string in place.
- It will throw InvalidOperationException at runtime.
Answers:
- Int32 index = 0; while (index < list.Count + 1) { if (list[index] == list[index + 1]) list.RemoveAt(index); else index–; }
- List<T> withDupes = LoadSomeData(); List<T> noDupes = new List<T>(new HashSet<T>(withDupes)); withDupes.AddRange(noDupes);
- List<T> withDupes = LoadSomeData(); List<T> noDupes = withDupes.Distinct().ToList();
- List<T> withDupes = LoadSomeData(); var hs = new HashSet<T>(withDupes); withDupes.All( x => hs.Add(x) );
Answers:
- Yes
- Yes, but they have to be derived from System.Exception class
- Yes, but they have to be derived from System.Object class
- No
Answers:
- Public
- Protected
- Private
- Static
class Test
{
static void Main() {
string myString = “1 2 3 4 5”
myString = Regex.Replace(myString, @”s+”, ” “);
System.Console.WriteLine(myString);
}
Answers:
- 12345
- 1 2 3 4 5
- 54321
- 5 4 3 2 1
Answers:
- System.Threading.Thread.Sleep(50);
- System.Threading.Thread.SpinWait(50);
- System.Threading.Thread.Yield();
- None of these.
public static byte[] ReadFully(Stream input)
{
using (MemoryStream ms = new MemoryStream())
{
input.CopyTo(ms);
return ms.ToArray();
}
}
Answers:
- It will work only in .NET Framework 4 or above, as the CopyTo function of the memory stream is available only in .NET Framework 4 or later versions.
- It will work only in .NET Framework 3.5 or below, as the CopyTo function of the memory stream is available only in .NET Framework 3.5 or earlier versions.
- It will work in all versions of the .NET framework.
- None of these.
Answers:
- Wait()
- Terminate()
- Join()
- Abort()
Answers:
- CLR
- JIT
- CTS
- GAC
- Satellite Assemblies
- All of these
Answers:
- The finally block is always executed before the thread is aborted.
- The finally block is never executed before the thread is aborted.
- The finally block is never executed after the thread is aborted.
- The finally block is always executed before the thread is started.
Answers:
- System.Assembly
- System.Reflection
- System.Collections
- System.Object
Answers:
- Predicate delegates are used for filtering arrays.
- Predicate delegates are references to functions that return true or false.
- Predicate delegates are only used in System.Array and System.Collections.Generic.List classes.
- Predicate delegates are only used in ConvertAll and ForEach methods.
List<Employee> lstEmployees = new List<Employee>
{
new Employee{Name=”Harry”,Age=15},
new Employee{Name=”Peter”,Age=22},
new Employee{Name=”John”,Age=45},
new Employee{Name=”Harry”,Age=15},
new Employee{Name=”Peter”,Age=22},
new Employee{Name=”John”,Age=45},
};
It is required to filter out employees having distinct names.
Which one of the following options cannot be used?
Answers:
- public class Employee { public int Age { get; set; } public string Name { get; set; } public override bool Equals(object obj) { return this.Name.Equals(((Employee)obj).Name); } public override int GetHashCode() { return this.Name.GetHashCode(); } } List<Employee> distinctEmployeesByName = lstEmployees.Distinct().ToList();
- public class Employee { public int Age { get; set; } public string Name { get; set; } } public class EmployeeEquityComparable : IEqualityComparer<Employee> { #region IEqualityComparer<Employee> Members public bool Equals(Employee x, Employee y) { return x.Name.Equals(y.Name); } public int GetHashCode(Employee obj) { return obj.Name.GetHashCode(); } #endregion } List<Employee> distinctEmployeesByName = lstEmployees.Distinct(new EmployeeEquityComparable()).ToList();
- public class Employee:IEqualityComparer<Employee> { public int Age { get; set; } public string Name { get; set; } #region IEqualityComparer<Employee> Members public bool Equals(Employee x, Employee y) { return x.Name.Equals(y.Name); } public int GetHashCode(Employee obj) { return obj.Name.GetHashCode(); } #endregion } List<Employee> distinctEmployeesByName = lstEmployees.Distinct().ToList();
- public class Employee { public int Age { get; set; } public string Name { get; set; } } List<Employee> distinctEmployeesByName = (from emp in lstEmployees group emp by emp.Name into gemp select gemp.First()).ToList();
Answers:
- It offers easier data binding from XAML.
- It’s interoperable with dynamic languages, which will be expecting DLR properties rather than dictionary entries.
- WPF data binding will understand dynamic properties, so WPF controls can bind to an ExpandoObject more readily than a dictionary.
- ExpandoObject can help in creating complex hierarchical objects. ExpandoObject implements the INotifyPropertyChanged interface, which gives more control over properties than a dictionary.
static void Main(string[] args)
{
int @int = 15;
Console.WriteLine(@int);
Console.ReadLine();
}
Answers:
- 15
- It will throw a compilation error.
- It will throw an error at runtime.
- @15
try {
// Code that might throw exceptions of different types
}
catch {
// Code goes here
}
Answers:
- Only errors of type std::unexpected are caught here.
- Other code exceptions are caught.
- This catch block must be the first one in a series of catch blocks that may or may not be followed.
- This catch block can be the last one in a series of catch blocks to handle any exception which is not handled by the preceding catch blocks, each of which handles an exception of a particular type.
- No errors are caught in this try block (they are all passed to the next closest catch).
- None of these.
Answers:
- Friend functions violate the concept of OOPS.
- Friend functions should not be used.
- Friend functions enhance the concept of OOPS if used properly.
- Friend functions are not available in C#.
string[] lines = theText.Split(new string[] { Environment.NewLine }, StringSplitOptions.None);
Answers:
- It splits the string variable on a system line break.
- It splits the string variable on a ‘rn’ line break.
- It splits the string variable on a system line break, while preserving the empty lines.
- It splits the string variable on a system line break, while removing the empty lines.
string s1 = “Old Value”;
string s2 = s1;
s1 = “New Value”;
Console.WriteLine(s2);
What will be the output printed, and why?
Answers:
- “New Value”, because string is a reference type.
- “Old Value”, because string is a value type.
- “New Value”, because string is a value type.
- “Old Value”, because string is a reference type.
- “Old Value”, because string is a reference type which is treated as a special case by the assignment operator.
private void Form1_Load(object sender, EventArgs e)
{
try
{
ThreadPool.QueueUserWorkItem(ShowMessage,null);
}
catch (Exception ex)
{
}
}
private void ShowMessage(object obj)
{
try
{
lblMessage.Text = “Hello from Thread Pool”;
}
catch (Exception ex)
{
}
}
Answers:
- lblMessage.Text will be set to “Hello from Thread Pool”.
- An InvalidOperationException will be thrown for the function ShowMessage as the UI can be updated only from the UI thread.
- Behavior will vary depending on the form loaded.
- None of these.
Answers:
- Additional assemblies that are used only by the main C# application
- User control assemblies used by the C# application
- Assemblies that contain only resource information and no code
- Assemblies that contain only code and no resource information
Answers:
- In the embedded resources of the assembly
- In the manifest of the assembly
- In the MSIL of the assembly
- In the Windows registry database
- None of these
“ttttt”
Answers:
- private string Tabs(uint numTabs) { IEnumerable<string> tabs = Enumerable.Repeat(“t”, numTabs); return (numTabs > 0) ? tabs.Aggregate((sum, next) => sum + next) : “”; }
- private string Tabs(uint numTabs) { StringBuilder sb = new StringBuilder(); for (uint i = 0; i <= numTabs; i++) { sb.Append(“t”); } return sb.ToString(); }
- private string Tabs(uint numTabs) { string output = “”; for (uint i = 0; i <= numTabs; i++) { output += ‘t’; } return output; }
- private string Tabs(uint numTabs) { String output = new String(‘t’, numTabs); return output; }
In C#, exception handling should be used…
Answers:
- to handle the occurrence of unusual or unanticipated program events
- to redirect the programs normal flow of control
- in cases of potential logic or user input errors
- in case of overflow of an array boundary
Answers:
- Can store two DLL files with the same name
- Can store two DLL files with the same name, but different versions
- Can store two DLL files with the same name and same version
- Cannot store DLL files with the same name
Answers:
- System.Reflection.Assembly.GetExecutingAssembly().CodeBase;
- System.Reflection.Assembly.GetExecutingAssembly().Location;
- AppDomain.CurrentDomain.BaseDirectory;
- None of these
Answers:
- Yes
- Yes, but they have to be marked with the keyword static.
- Yes, but they have to be marked with the keyword internal.
- No
Answers:
- var name = InvokeMemberName.Create; Impromptu.InvokeMemberAction(this, name(“GenericMethod”, new[]{myType}));
- MethodInfo method = typeof(Sample).GetMethod(“GenericMethod”); MethodInfo generic = method.MakeGenericMethod(myType); generic.Invoke(this, null);
- Action<> GenMethod = GenericMethod< myType >; MethodInfo method = this.GetType().GetMethod(GenMethod.Method.Name); MethodInfo generic = method.MakeGenericMethod(myType); generic.Invoke(this, null);
- Action<> GenMethod = GenericMethod< myType >; MethodInfo method = this.GetType().GetMethod(“GenericMethod”); MethodInfo generic = method.MakeGenericMethod(myType); generic.Invoke(this, null);
Answers:
- It is an interoperation between managed code, COM objects, and pre-existing DLL’s (unmanaged code and data).
- It is a software Output Unit of Deployment and a unit of versioning that contains MSIL code.
- It is the primary building block of a .NET Framework application and a collection of functionality that is built, versioned, and deployed as a single implementation unit.
- All of these.
class X {
private int i;
protected float f;
public char c;
}
class Y : X { }
Answers:
- c
- f
- i
- All of these
Answers:
- //source code i += i++; //abstract syntax tree += / i i (post) ++
- // source code i += i++; //abstract syntax tree += / i ++ (post) i First, i++ returns 0. Then i is incremented by 1. Lastly i is set to the initial value of i which is 0 plus the value i++ returned, which is zero too. 0 + 0 = 0.
- int i = 0; i = i + i; i + 1;
- int ++(ref int i) { int c = i; i = i + i; return c;}
Answers:
- int FindSum(object[] values) { int sum = 0; foreach (object o in values) { if (o is int) { int x = (int) o; sum += x; } } return sum; }
- int FindSum (object[] values) { int sum = 0; foreach (object o in values) { int? x = o as int?; if (x.HasValue) { sum += x.Value; } } return sum; }
- int FindSum (object[] values) { int sum = values.OfType<int>().Sum(); return sum; }
- int FindSum (object[] values) { int sum = 0; foreach (object o in values) { if (o is int) { int x = Convert.ToInt32(o); sum += x; } } return sum; }
public class Person
{
public string GetAge()
{
lock (this)
{
// Code to get Age of this person object.
}
}
}
Which of the following statements is true?
Answers:
- lock(this) actually modifies the object passed as a parameter, and in some way makes it read-only or inaccessible.
- lock(this) can be problematic if the instance can be accessed publicly, because code beyond one’s control may lock on the object as well. This could create deadlock situations where two or more threads wait for the release of the same object.
- lock(this) marks current object as a critical section by obtaining the mutual-exclusion lock for a given object, all private fields of the object become read-only.
- Implement locking using current application instance or some private variable is absolutely the same and does not produce any synchronization issue, either technique can be used interchangeably.
Answers:
- System
- System.CodeDom
- System.IO
- System.Thread
- System.Text
Answers:
- A constructor can return values, but a member function cannot.
- A member function can declare and define values, but a constructor cannot.
- A member function can return values, but a constructor cannot.
- All of these.
Answers:
- Visual Basic
- C#
- C++
- Jscript
A) lock(this.locker) this.counter++;
B) Interlocked.Increment(ref this.counter);
C) Change the access modifier of counter to public volatile
Which statement is incorrect with regards to these approaches?
Answers:
- All 3 are equivalent and can be used interchangeably.
- Though A is safe to do, it prevents any other threads from executing any other code which is guarded by locker.
- B is the best approach as it effectively does the read, increment, and write in ‘one hit’ which can’t be interrupted.
- C on it’s own isn’t actually safe at all. The point of volatile is that multiple threads running on multiple CPU’s can, and will, cache data and re-order instructions.
public class var { }
public class main
{
public static void main(string[] args)
{
var testVar = new var();
}
}
Answers:
- This code will not compile, as var is a reserved keyword, so it can not be used as a class name.
- This code will compile, as var is merely a contextual keyword and it is used to provide a specific meaning in the code, so it will cause no problems.
- This code will not compile, as a new object cannot be created like var testVar = new var();
- None of these.
Answers:
- Inheritance
- Data hiding
- Polymorphism
- Operator overloading
- Abstraction
Answers:
- *
- ::
- &
- ?:
- <<
Answers:
- MSIL
- Unmanaged code
- Managed Code
- C#/VB/JS
Answers:
- ExecuteReader
- ExecuteScalar
- ExecuteNonQuery
- All of these
Answers:
- The Common Language Runtime
- A set of class libraries
- The Common Language Runtime and a set of class libraries
[Flags]
public enum Permissions
{
None = 0,
Read = 1,
Write = 2,
Delete = 4
}
What will be the output of the following Main program (which has access to the enum defined above) in this C# console application (Assume required namespaces are included) :
static void Main(string[] args)
{
var permissions = Permissions.Read | Permissions.Write;
if ((permissions & Permissions.Write) == Permissions.Write)
{
Console.WriteLine(“Write”);
}
if ((permissions & Permissions.Delete) == Permissions.Delete)
{
Console.WriteLine(“Delete”);
}
if ((permissions & Permissions.Read) == Permissions.Read)
{
Console.WriteLine(“Read”);
}
Console.ReadLine();
}
Answers:
- Write Delete Read
- Write Delete
- Delete
- Write Read
Answers:
- abstract
- sealed
- final
oot - internal
protected internal class A
{
}
Which statement is correct with regards to its accessibility?
Answers:
- This class can be accessed by code in the same assembly, or by any derived class in another assembly.
- This class can only be accessed by code which is in the same assembly.
- This class can only be accessed by code which is in the derived class (i.e. classes derived from Class A) and which are in the same assembly.
- This class can be accessed by any code whether in the same assembly or not.
Answers:
- Random random = new Random(); List<object> products= GetProducts(); products.OrderBy(product => random.Next(products.Count));
- Random random = new Random(); List<object> products= GetProducts(); products.Randomize(product => random.Next(products.Count));
- Random random = new Random(); List<object> products= GetProducts(); products.Randomize(products.Count);
- Random random = new Random(); List<object> products= GetProducts(); products.Reverse(product => random.Next(products.Count));
int num1 = 10, num2 = 9;
int result = num1 & num2;
Answers:
- 1
- 8
- 9
- 10
- 11
- 109
class CCheck {
public static void Main() {
string str = @”E:\RIL\test.cs”;
Console.WriteLine(str);
}
}
Answers:
- “E:\RIL\test.cs”
- E:\RIL\test.cs
- “E:RILtest.cs”
- The compiler will generate an error saying undefined symbol ‘@’.
public string GetName(int iValue)
{
string sValue = “0”;
switch (iValue)
{
case 1:
sValue = iValue.ToString();
case 2:
sValue = iValue.ToString();
break;
default:
sValue = “-1”;
break;
}
return sValue;
}
Answers:
- The code will not compile as there shouldn’t be a break statement in the default case label.
- The code will compile but if case 1 is passed as the input parameter to the function, the code for case 2 will also execute (after the code for case 1), and so the wrong value may be returned.
- The code will compile and run without any issues.
- The code will not compile as there is no break statement in case 1.
static void Main(string[] args)
{
for (int i = 0; i < 1; i++)
{
Console.WriteLine(“No Error”);
}
int A = i;
Console.ReadLine();
}
Answers:
- No Error
- This program will throw a compilation error, “The name ‘i’ does not exist in the current context”.
- The program will compile, but throw an error at runtime.
- None of these.
Answers:
- int represents a 16-bit integer while System.Int32 represents a 32-bit integer.
- int is just an alias for System.Int32, there is no difference between them.
- int represents a 64-bit integer while Int32 represents a 32-bit integer.
- None of these.
public int fn(int var)
{
int retvar = var – (var / 10 * 5);
return retvar;
}
Answers:
- 50
- 25
- 49
- Error message
- None of these
Answers:
- public static string ConvertToString(IEnumerable<T> source) { return new List<T>(source).ToArray(); }
- public static string ConvertToString(IEnumerable<T> source) { return string.Join(“,”,source.ToArray()); }
- public static string ConvertToString(IEnumerable<T> source) { return source.ToString(); }
- public static string ConvertToString(IEnumerable<T> source) { return string.Join(source.ToArray()); }
Answers:
- An empty collection and a null are both objects.
- An empty collection and a null both have the same meaning.
- Both an empty collection and a null do not refer to any object.
- An empty collection is an object while the null keyword is a literal.
Answers:
- IOException
- SecurityException
- UnauthorizedAccessException
- InvalidOperationException
Answers:
- A variable that is passed as an out parameter needs to be initialized, but the method using the out parameter does not need to set it to something.
- The out parameter can be used to return the values in the same variable passed as a parameter of the method. Any changes made to the parameter will be reflected in the variable.
- The ref keyword can only be used on one method parameter.
- The ref parameter is considered initially assigned by the callee. As such, the callee is not required to assign to the ref parameter before use. Ref parameters are passed both into and out of a method.
Answers:
- String objects are mutable, while StringBuilder objects are immutable.
- String objects are immutable, while StringBuilder objects are mutable.
- There is no difference between them in this context, as both are immutable.
- There is no difference between them in this context, as both are mutable.
Answers:
- public static T[] ToArray(IEnumerable<T> source) { return new List<T>(source).ToArray(); } IEnumerable<string> strings = …; string[] array = Helpers.ToArray(strings); string joined = string.Join(“,”, strings.ToArray()); string joined = string.Join(“,”, new List<string>(strings).ToArray());
- List<string> ls = new List<string>(); ls.Add(“one”); ls.Add(“two”); string type = string.Join(“,”, ls.ToArray());
- string commaSeparatedList = input.Aggregate((a, x) => a + “, ” + x)
- public static string Join(this IEnumerable<string> source, string separator) { return string.Join(separator, source); }
Answers:
- IList<T> uses reflection, which is the most efficient way to process an object inside memory.
- IList<T> implements hashing to store objects in the collection; which produces optimum performance.
- Using IList<T> rather than List<T> allows the code to be more flexible. It can replace the implementation with any collection that implements IList<T> without breaking any calling code.
- IList<T> only allows immutable types to be stored inside the collection.
Answers:
- System.Threading.SingleInstance can be used to ensure that only one instance of a program can run at a time.
- System.Threading.Mutex can be used to ensure that only one instance of a program can run at a time.
- Locks can be used to force a C# application to launch a single instance at a time.
- C# applications cannot be restricted to a single instance.
Answers:
- System.Diagnostics.Process pProcess = new System.Diagnostics.Process(); pProcess.StartInfo.FileName = strCommand; pProcess.StartInfo.Arguments = strCommandParameters; pProcess.StartInfo.UseShellExecute = false; pProcess.StartInfo.RedirectStandardOutput = true; pProcess.Start(); string strOutput = pProcess.StandardOutput.ReadToEnd(); pProcess.WaitForExit();
- Process p = new Process(); p.StartInfo.UseShellExecute = true p.StartInfo.RedirectStandardOutput = false p.StartInfo.FileName = “YOURBATCHFILE.bat”; p.Start(); string output = p.StandardOutput.ReadToEnd(); p.WaitForExit();
- System.Diagnostics.ProcessStartInfo psi = new System.Diagnostics.ProcessStartInfo(“program_to_call.exe”); psi.RedirectStandardOutput = true; psi.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden; psi.UseShellExecute = false; System.Diagnostics.Process proc System.Diagnostics.Process.Start(psi);; System.IO.StreamReader myOutput = proc.StandardOutput; proc.WaitForExit(2000); if (proc.HasExited) { string output = myOutput.ReadToEnd(); }
- System.Diagnostics.Process pProcess = new System.Diagnostics.Process(); pProcess.StartInfo.FileName = strCommand; pProcess.StartInfo.Arguments = strCommandParameters; pProcess.StartInfo.UseShellExecute = false; pProcess.StartInfo.RedirectStandardOutput = true; pProcess.StartInfo.WorkingDirectory = strWorkingDirectory; pProcess.Start(); string strOutput = pProcess.StandardOutput.ReadToEnd(); pProcess.WaitForExit();
Answers:
- An Action is a delegate to a method, that takes zero, one or more input parameters, but does not return anything.
- An Action is a delegate to a method, that takes zero, one or more input parameters, but always returns a boolean value.
- An Action is a delegate to a method that takes one or more input parameters, but does not return anything.
- An Action is a delegate to a method that takes one or more input parameters, but always returns a boolean value.
Answers:
- There is no difference between the two.
- Func<T> denotes a delegate, while Expression<Func<T>> denotes a tree data structure for a lambda expression.
- Func<T> denotes a function with parameter of dynamic type, while Expression<Func<T>> denotes a lambda expression.
- None of these.
Answers:
- IEnumerable<T> supports a Size property.
- IEnumerable<T> supports a Count() extension.
- IEnumerable<T> cannot be casted onto an ICollection<T>.
- IEnumerable<T> cannot be casted onto an IList<T>.
Answers:
- It’s a string containing “n” for non-Unix platforms.
- It’s a string containing “n” for Unix platforms.
- It’s a string containing “rn” for non-Unix platforms.
- It’s a string containing “rn” for Unix platforms.
Answers:
- IS A
- HAS A
- CAN DO
- None of these
Answers:
- Iteration variables can cause problems with accessing a modified closure.
- Iteration variables are passed by value, which produces unexpected results.
- Iteration variables are passed by reference, which produces unexpected results.
- It is perfectly valid to use iteration variables in lambda expressions.
Answers:
- protected virtual bool IsFileLocked(FileInfo file) { FileStream stream = null; try { stream = file.Open(FileMode.Open, FileAccess.ReadWrite, FileShare.None); } catch (IOException) { return true; } finally { if (stream != null) stream.Close(); } return false; }
- try { using (Stream stream = new FileStream(“MyFilename.txt”, FileMode.Open)) { } } catch { }
- internal static bool FileOrDirectoryExists(string name) { return (Directory.Exists(name) || File.Exists(name)) }
- FileInfo file = new FileInfo(“file.txt”); if (file.Exists) { // TO DO }
A:
try {
// code goes here
} catch (Exception e) {
throw e;
}
B:
try {
// code goes here
} catch (Exception e) {
throw;
}
Answers:
- A will lose the call stack trace information. B will preserve the call stack trace information.
- A will preserve the call stack trace information. B will lose the call stack trace information.
- Both A and B will preserve the call stack trace information.
- Both A and B will lose the call stack trace information.
Answers:
- By using the System.Runtime.Serialization.Formatters.Binary.BinaryFormatter class.
- By using the System.Reflection.DeepCopy class.
- By using the DeepCopy() method of Object class.
- By using the MemberwiseClone() method of Object class.
static void Main(string[] args)
{
string Invalid = “$am$it$”;
string sResult = Invalid.Trim(new char[]{‘$’});
Console.WriteLine(sResult);
Console.ReadLine();
}
Answers:
- amit
- am@am$
- $am$it$
- am$it
Answers:
- var results = from myRow in myDataTable where results.Field(“RowNo”) == 1 select results;
- var results = from myRow in myDataTable.AsEnumerable() where myRow.Field(“RowNo”) == 1 select myRow;
- var results = from myRow in myDataTable.Rows where myRow.Field<int>(“RowNo”) == 1 select myRow;
- var results = from myRow in myDataTable.AsEnumerable() where myRow.Field<int>(“RowNo”) == 1 select new { IID= myRow.Field<int>(“IID”), Date = myRow.Field<DateTime>(“Date”), };
Answers:
- It is used to improve the performance of the Visual Studio debugger.
- It is used to improve the performance of Visual Studio plugins.
- It is used to improve the performance of the C# compiler.
- It is used to load Visual Studio configuration data.
1.
catch (Exception exc)
{
throw exc;
}
2.
catch (Exception exc)
{
throw;
}
Answers:
- 1 is better as it maintains the call stack.
- 2 is better as it maintains the call stack.
- Both are same.
- None of these.
int num1 = 10, num2 = 9;
int result = num1 ^ num2;
Answers:
- 1
- 8
- 9
- 10
- 3
- 1000000000
- 109
static void Main(string[] args)
{
string sPrint = String.Format(“{{ My name is bond. }}”);
Console.WriteLine(sPrint);
Console.ReadLine();
}
Answers:
- {{ My name is bond. }}
- It will throw a compilation error.
- { My name is bond. }
- It will throw a runtime error.
Answers:
- string is a value type, while System.String is a reference type.
- There is no difference,string is just an alias of the System.String data type.
- string variable is limited to storing alphabetic characters, while System.String does not have any limit.
- None of these.
Workbooks books = excel.WorkBooks;
Workbook book = books[1];
Sheets sheets = book.WorkSheets;
Worksheet ws = sheets[1];
Answers:
- Marshal.ReleaseComObject(books);
- Marshal.FinalReleaseComObject(books);
- Marshal.ReleaseComObject(sheets); Marshal.ReleaseComObject(books);
- Marshal.ReleaseComObject(sheet); Marshal.ReleaseComObject(sheets); Marshal.ReleaseComObject(book); Marshal.ReleaseComObject(books);
Answers:
- List<KeyValuePair<string, string>> myList = aDictionary.ToList(); myList.Sort( delegate(KeyValuePair<string, string> firstPair, KeyValuePair<string, string> nextPair) { return firstPair.Value.CompareTo(nextPair.Value); } );
- List<KeyValuePair<string, string>> myList = aDictionary.ToList(); myList.Sort((firstPair,nextPair) => { return firstPair.Value.CompareTo(nextPair.Value); } );
- foreach (KeyValuePair<string,int> item in keywordCounts.OrderBy(key=> key.Value)) { // do something with item.Key and item.Value }
- var ordered = dict.OrderBy(x => x.Value);
No comments:
Post a Comment