h1.post-title { color:orange; font-family:verdana,Arial; font-weight:bold; padding-bottom:5px; text-shadow:#64665b 0px 1px 1px; font-size:32px; } -->

Pages

Reverse string using C#.Net

Here i will give method for displaying reverse of string value using C#.net
ReverseValue is a method for display reverse of string.

public static string ReverseString(string str)
        {
            int length =str.Length -1;
            while (length >-1)
            {
                stringresult = stringresult + str[length];
                length--;
            }
            return stringresult;
        }
Call method : 
  string str = DerivedClass.ReverseString("LAKSHMI");
    MessageBox.Show(str.ToString());

C#.net Interview Question with Anwers

What is use of System.Environment?
Retrieve Information about from Operating System.
How many Comments in C#.net?
S.No Comment Symbol Comment Descr
1     //          Single-Line Comment
2     /* */          Muliti-Line Comment
3     ///             XML Doc Comment.
Can we put multiple catch blocks in a single try statement in C#?
Yes. Multiple catch blocks may be put in a try block.
What are the different types of assemblies - name them?
1)Private2)Public/Shared3)Satellite assembly.
How many types of JIT compilers are available?
1)standard JIT compiler.2)EconoJIT compiler.
How to declare an array for int?    
int[] n;
Here,
int -- Data Type
[] -- Name of the Array
n -- name
what are the Non-UI Controls into Component tray in C#.net?
Timer,Backgroundworker.
What is mean by "Extractor Method" in C#.net?How do i get?
Extractor Method:
you can create a new method by extracting a selection of code from inside the code block of an existing member. The new method is created containing the selected code, and the selected code in the existing member is replaced with a call to the new method.
Select a Code >>Right Click >>select "Refactor">> Select "Extractor Method" >>create method name in the Screen and Click Ok.
What are the Methods and Property of Thread?
Methods :Invoke(),BeginInvoke(),EndInvoke(),CreateGraphics()
Property:InvokeRequired
Note:These are Thread-Safe.
Define Interfaces
properties and methods of classes, but unlike classes, do not provide implementations. The Interface statement allows you to declare interfaces, while the Implements statement lets you write code that puts the items described in the interface into practice.
Define User Controls Class?
User Controls are created by the user and are based on the class UserControl (System.Windows.Forms.UserControl). User controls too have properties, methods and events.
What is the top .NET class that everything is derived from?
System.Object.
what are the Access specifiers in C#?
Public, Private, Protected, internal, protected internal.
How to assign a value to a readonly variable in C#?
using constructor
Can you store multiple data types in System.Array?
No.
can we put the Break statement in Finally block?
No.
Does C# Support Static Indexer?
No , It supports instance indexer.
Difference between convert.Tostring() and .Tostring()?
Convert.Tostring() : Support Null Value.
.ToString(): Not support null value.
How do you create empty strings in C#?
Using string.empty
EX:
String EString = String.Empty;
Are structs value types or reference types?
it is a value Type.
What do you mean by casting a data type?
Converting a variable of one data type to another data type is called casting. This is also called as data type conversion.
How can you sort the elements of the array in descending Order?
By calling Sort() and then Reverse() methods.
How do you inherit from a class in C#?
Place a colon and then the name of the base class.
What is Anchoring a control and Docking a control?
Anchoring: used to resize controls dynamically with the form.
Docking: to adhere to the edges of its container.
Differentiate between instance data and class data?
Class data in terms of static class is the data that particular class holds in its structure.
Instances can refer to different objects of the same class that hold different values using the same class structure in memory heap.
what is bitarray?
Collection of Bit values.
Is there an alternative of exit() for quitting a C# .NET application?
System.Environment.Exit(int exitCode)/Application.Exit()
What does the term immutable mean?
Data value may not be changed.
What is the difference between the Array.Clone() and Array.CopyTo() ?
Array.Clone -- method returns a new array object containing all the elements in the original array.
Array.CopyTo -- method copies the elements into another existing array.
difference between IS and AS Operator?
IS: Expression evaluates True.Expression is not null.Expression can be cast to type.
as: cast except that it yields null on conversion failure instead of raising an exception.
If casting fails what type of exception is thrown?
InvalidCastException.
Difference between throw and throw ex?
Throw : Original error stack information.
Throw ex: stack error of the exception will be replaced with a stack trace starting at the re-throw point.
Difference between Out and Ref ?
Out :Only for Output Parameter.
Ref: Both In/Output Parameter.
Can you call a WIN32 API function from c# Program?
Yes
How do you call a Member method and pass a value Type by reference?
use the "ref" keyword when declaring a Parameter of the Method
Ex:
public bool GetValue(ref int returnvalue);
How do you declare a Numeric type to String?
Call System.Object.Tostring()
For Example
int idx =0;
string str - idx.ToString();
Does C# support friend class?
no.
what is Purpose of using Return Statement?
returns flow of control from a method to the caller,optionally,passing by a return value.
what is Purpose of using Continue Statement?
It will pass a flow of Control immediately to start of a loop
what is Purpose of using Break Statement?
Exists from the Loop of a FOR,WHILE or DO WHILE Statement
How to use Pascal and camel case in a Program?
Pascal Casing :First Character of all words are upper case and other characters are lower case.
Ex:
ForeColor
Camel Casing: First charater of all words,except the first word are upper case and Other characters are lower case.
EX:
foreColor
Pascal Casing :Class Name and Method Name
Camel Casing: Variables and Method Parameter .
Which object allows for faster reading of data the Datareader or Dataset?
Datareader.
how to get Default value in C#.net?
use Default Keyword.
Can you override private virtual methods?
No.
What does the keyword virtual mean in the method definition?
over-ridden.
What is use of C# "Default" Keyword?
Initialize default value for its type
What is the difference between an EXE and a DLL?
Dll is an In-Process Component whereas EXE is an Out-process Component.
What is the Type of errors?
1)Configuration Errors2)Parser Errors3)Compilation Errors4)Run-Time Errors.
what is a thread?
basic unit to which the operating system allocates processor time.
What the way to stop a long running thread ?
Thread.Abort()
How can you reference currentThread of the Method?
Thread.Currentthread
what are the Different level of ThreadPriority?
1) ThreadPriority.Highest2) ThreadPriority.AboveNormal3) ThreadPriority.Normal4) ThreadPriority.BelowNormal5) ThreadPriority.Lowest.
how would you remove the blank entry from array in C#.Net?
Use "StringSplitOptions.RemoveEmptyEntries" in the Array string
like this:
String[] tolist = test.Split(new []{',', ' ', ';'}, StringSplitOptions.RemoveEmptyEntries);
what is the use of Reflection?
Reflection is used to Get assembly metadata using code.
Difference between constant and readonly in C#.net
Constant : Modify a declaration of a fields or Local variable.
Readonly: Modify that you can on field.
what is use of Trim() function and explain different variation ?
Trim function:
remove off Space character from the Beginning and from Ending of the instance.
different Variation in the Trim function:
1)Trim() 2)TrimStart() 3)TrimEnd()
1) Trim():Simply says, remove off spacing from the Start and End of the Instance or string.
2) TrimStart():Simply says, Remove off spacing from the Start of the Instance or String.
2) TrimEnd():Simply says, Remove off spacing from the End of the Instance or String .
what is mean by Trace Class?
Trace class builds both Debug and release.
Whats the use of "throw" keyword in C#?
The throw keyword is used to throw an exception programatically in C#.
Is it Possible to declare an array variable without initialization?
Yes. It is possible .Use "New" keyword.
Eg:
int[] myArray;
myArray = new int[] {1,3,5,7,9};
Difference between Boxing and unboxing?
Boxing: Convert value type to reference type.
UnBoxing:Convert Reference type to value Type.
which is a basis for event?
Delegates are basis of events.
what are different types of Delegates?
1. Single cast delegate 2. Multicast delegate.
Explain Types of Data Source in .net?
DataSource: Allow data binding on Win Form Controls.
Types of DataSource:
1) Database 2) Service3) Object.
Database :Lets you connect to a database and choose the database objects for your application. This option creates a dataset.
Service:Opens the Add Service Reference dialog box that lets you create a connection to a service that returns the data for your application.
Object:Lets you choose an object that can later be used to generate data-bound controls.

Exception Handling

  •     It is a Errors,innocent Errors,silly errors.
  •     Programmer spends as much time to fixing errors as in programming.
Categorize of Errors:
1)Grammatical or Syntax errors.2)Linker errors.3)Run Time errors.
Grammatical or Syntax errors:
   it occurs when Syntax goes errors.
Linker errors:
   It occurs when we try to access some library function and for some reason or the other function ca not found out.
Run Time errors:
    It occurs at time of exception of the Program.
Common reasons for Exceptions:
1) Failing short of memory.2)Dividing value of Zero.3)Inability to open a file.
4)Exceeding the bound of an array.5)Attempting to initialize an object to an impossible value.
How to handle exception in C#.net?
1)The try block followed by one more catch blocks.
2)The try-catch blocks followed by finally block.

1)try-catch blocks:
try block contains code executed to raise an exception.
2)try-catch-finally blocks:
finally block used to perform clean up operation before the program ends.
thrown Statement:
   The thrown statement is used to thrown exception explicitly.

User Defined Exceptions:
  At such time we need to defined exceptions if the rules are violated.
  Our exception class should be derived from the System.Exception class.

Compare string in C#.net


In this Article, we discuss about a string Compare and split a strings.
t is a sample code for Compare string.
 In My project, I used 4 controls.The controls are Two Textbox ,One Label and One Button.
  Here, I create a simple function for Comparing two string using C#.net .
  Input :
      1st TextBox: My name is Lakshmi Naraayanan
      2nd TextBox: My name is Naraayanan   
Output:
     Lakshmi.

Code:
  
private string  CompareText(string fValue,string svalue)
 {
            string formHeading = fValue;
            string userSearch = svalue ;
            string constring = string.Empty;
            string comstring = string.Empty;
            string[] formHeadingWords;
            string[] userSearchWords;
 formHeadingWords = System.Text.RegularExpressions.Regex.Split(formHeading, @"\W");
 userSearchWords = System.Text.RegularExpressions.Regex.Split(userSearch, @"\W");
            int cntFarray = formHeadingWords.Length;
            int cntSarray = userSearchWords.Length;
            if (cntSarray > cntFarray)
            {
                foreach (string _str in userSearchWords)
                {
                    if (!formHeading.Contains(_str))
                    {
                       comstring = _str;
                    }
                    if (comstring.Trim() != constring.Trim())
                    {
                        constring = constring + " " + comstring;
                    }
                }
            }
            else
            {
                foreach (string _str in formHeadingWords)
                {
                    if (!userSearch.Contains(_str))
                    {
                        comstring = _str;
                    }
                    if (comstring.Trim() != constring.Trim())
                    {
                       constring = constring + " " + comstring;
                    }
                }
            }
           return constring;
         }
call this button click event:
  string str = CompareText(textBox1.Text,textBox2.Text );
            label1.Text = str;
            label1.ForeColor = Color.Red;

Use Modules and Class method in the VB.Net

First , we must know Modules and Class in the VB.Net.
Modules:
Modules are VB counterparts to C# static classes.
you don't want to allow inheritance and instantiation, you use a Module.
Class:
A class is a collection of objects of similar type. Once a class is defined, any number of objects can be created which belong to that class.
 Methods
A Method is a procedure built into the class. They are a series of statements that are executed when called.
Sub Procedures
Sub procedures are methods which do not return a value. Each time when the Sub procedure is called the statements within it are executed until the matching End Sub is encountered.
Function is a method which returns a value. Functions are used to evaluate data, make calculations or to transform data. Declaring a Function is similar to declaring a Sub procedure. Functions are declared with the Function keyword.
Example call Module function  and Class methods
Here , i give a program for get splitting a string using function in VB.net
In vb.Net Function will return a value.

Module Module1
    Function splittingvalue(ByVal strigs As String, ByVal sr As Char) As String()
        Dim st As String() = strigs.Split(New Char() {sr})
        Return st
    End Function

Public Class Class1

    Public Shared Sub displaymessage()
        MessageBox.Show("Good Luck")
    End Sub

End Class

How to call Functions and Methods in the Application?
  Class1.displaymessage() // Method...
  Dim result As String() = Module1.splittingvalue("Lakshmi", "k") // Function
  Dim conResult = result(0) + result(1)
  MessageBox.Show(Convert.ToString(conResult))