Tuesday, 4 August 2015

String Vs string ?

string is an alias of System.String. string is reserved keyword in c# .net. Int32 Vs int is a similar situation as is BooleanVs bool.  To use string any time refering to an object.

Ex:-
string place = ”world”;

String (System.String) is a class in the base class library. To use String if you need to refer specially to a class.

Ex:-
string strText = String.Format("Helo {0}", place);

So technically there is no difference between string and String.

What is Nullable in.Net and how to use?

C# provided a special data type called as Nullable type. In Nullable type you can assign a normal range values i.e  -2,147,483,648 to 2,147,483,647 or null value also.

In int,string,float,double etc data type we can not assign null values.

int intNo = null; // compiler error : Cannot convert null to int because it is non-nullable value type

Syntax:

<data_type>?  <variable-name> = null;

Example :-

static void Main(string[] args)
{
   int? num = null;
   int? num = 45;
   string strWord = null;
   double? d = 3.478;
   object o = null;
   Console.WriteLine("{0},{1},{2},{3},{4}",num,num1,strWord,d,o);
   Console.ReadLine();
}


Output:   , 45 ,  ,3.478,

Wednesday, 8 July 2015

Difference between Union and Union All in sql server 2008?

Union gives distinct value from combination of two tables while Union All gives value with duplication from combination of two tables.
In Union result set is sorted in ascending order while In Union All result set is not sorted, two query output gets appended.

Union Vs UnionAll in Sql server 2008?

Union:-
1. It is used to combine the result set of two or more SELECT statement.
2. Each SELECT statement within the UNION must have the same no of columns.
3. Columns must have the similar data type.
4. Columns in each SELECT statement must be in the same order.
5. Union operator Select distinct value by default.

Union All:-
1. It is used to combine the result set of two or more SELECT statement.
2. Each SELECT statement within the UNION ALL must have the same no of columns.
3. Columns must have the similar data type.
4. Columns in each SELECT statement must be in the same order
5. Union All select all the value i.e Union All will not eliminate duplicate value

Tuesday, 7 July 2015

In c#, the variable which is declared inside a class but not I a method is called as?

The variable which is declared inside a class but not inside the method is called as instance variable.

Instance variable does not include any static modifier in the class and also they operate on instance of a class.

In c#, what is the keyword used to access the base class members within the derived class?

‘base’ is c# keyword used to access the base class members. It just give the permission to access  to the constructor, instance property accessor or a instance method. We  cannot use ‘base’ keyword in static method.

Monday, 6 July 2015

What is implementation inheritance and interface inheritance?

When a class is derived from another class in such a way that it will inherits all its member to its corresponding derived class then it is implementation inheritance.
When a class inherits only the signatures of the functions or methods from its corresponding base class, then it is called as interface inheritance.

Monday, 29 June 2015

Object reference not set to an instance of object?

If this type of error you are getting anywhere in .net application means some parameter or object passing null values to a method.
Check the value against null. Somewhere null values/values  are/is passing.

Which class can not be inherited from object class?

None!. All clases are inherited from system.object clas. If class not inherited from system.object class then why all the class have .ToString(),GetHashCode and other object inherited functions.
I have read many blogs and answers some are saying that sealed and abstract class can not be inherited from system.object class. But it is wrong.

System.Object class is the parent class of all the classes. By the definition of class sealed and abstract class , definitions saying that you can inherite the class or you cann’t make derived from these class . It is not saying it s not inherited from system.Object class. So we definitely say that all the class is inhetited from system.Object class.

Can we call static method from abstract class in c#?

Yes. We can call static method from abstract class. Static method does not required instance of class. Object of abstract class can’t be created but to call static object  is not required. So we can call static method with abstract class name i.e abstractclass.methodname();

Example :-

public abstract class Abstractest
    {
        public static string Test()
        {
           return  "Static method in abstract class";
        }
    }
static void Main(string[] args)
        {
            Abstractest.Test();
            Console.ReadLine();
        }

What is mean by Partial class?

It is new features in .Net 2.0; partial classes mean that class definition can be split into multiple physical files. Logically,......
                                                                                                                           Read More

What is mean by Partial class?

It is new features in .Net 2.0; partial classes mean that class definition can be split into multiple physical files. Logically, partial classes do not make any difference to the compiler. The compiler intelligently combines the definitions together into a single class at compile-time

Customer1.cs:-
partial class Customer
    {
        int age;
        public int Age
        {
            get { return age; }
            set { age = value; }
        }
        public void GetDeyails(int id)
        {
            GetEmpName(id);
        }
        partial  void GetEmpName(int id)
        {
            Console.Write("Employee1");
        }
    }

customer1.cs
partial class Customer
    {
        string name ;
        public string Name
        {
            get { return name; }
            set { name = value; }
        }
         partial void GetEmpName(int id);
    }

static void Main(string[] args)
{
 Customer cust = new Customer();
            cust.Name = "SKM";
            cust.Age = 123;
            //string res;
            cust.GetDeyails(1);
}

Thursday, 18 June 2015

We all know in Try-catch-finally block finally is called every time whether exception came or not, but in which condition or scenario finally block will not called?

As we know that finally block will called every time whether exception occurred or not, but in some scenario finally will not called.

Finally block will not called in the following scenario:-
1.) System.ExecutionEnginException
2.) System.StackOverFlowException
3.) Page state is changed inside try block

Where the class variable and globle variable get stored after the class object created?

When object of class created then
1.) Class level variables stored in Heap.
2.) Value type variables stored in stack.

Difference between string.Empty and “ ”?


String.Empty  will not create any object of String while “ “ will create a new  object in the memory.
.Length == 0 is the fastest option , but .Empty makes slightly cleaner code.
String.Empty is read-only field while “ “ is compile time constant.

Wednesday, 10 June 2015

CHARINDEX function in Sql Server2008?

CHARINDEX function is used to get starting position of specified expression in a string.

Syntax of CHARINDEX function :-

CHARINDEX(expression1,(expression2[,Start_Location])

expression1 is a sequence of character to be found in expression2. It is of short character datatype.

expression2  is a string in which expression1 to be search. It is of character string datatype.

Start_Location is position to start searching expression1 in expression2 .It is an optional field. If you will provide anything then it start search from position 0.

Examples:-

Example1:-

DECLARE @cust varchar(300),@pos int
set @cust='a,b,c,d'
Select CHARINDEX(',',@cust,1)

Output:-
2

Example2:-

Select CHARINDEX('am','Example-syntax-Example',1)

Output:-
3

Friday, 5 June 2015

Table A have 5 rows and Table B have 7 rows. How many rows does “Select * from A, B” return?

It will return 35 rows.

Table A have 5 columns and Table B have 7 columns. How many columns does “Select * from A, B” return?

It will return 12 columns.

How to get all tables name from database in SQLServer 2008?

To get all tables names from DataBase:-

select * from information_schema.tables
Select * from SYS.TABLES

What is the purpose of HTTP, SOAP in web service?

Client application method call goes to proxy, proxy covert method call to xml format that is soap message.
SOAP message will reach web server via HTTP protocol.
Webserver create the object of web service and execute the method.
The result in the form of soap format is given to client back over HTTP.