Posts

Showing posts from March, 2014

Can we implement interface with same method name?

Interface is similar to a class, and we implement interface by defining their method in class. Suppose we have same method in more than one interface.

In this case there will be a question for interview.

Q.    Can we implement interface with same method name?
Ans. Yes by using explicit interface implementation.

Lets see below example:

class Program
    {
        static void Main(string[] args)
        {
            MyInterface1 obj1 = new MyClass();
            MyInterface2 obj2 = new MyClass();

            obj1.func1();
            obj2.func1();
        }
        interface MyInterface1
        {
            void func1();
        }

        interface MyInterface2
        {
            void func1();
        }

        class MyClass : MyInterface1, MyInterface2
        {
            void  MyInterface1.func1()
            {
                Console.WriteLine("Hello1");
            }

            void MyInterface2.func1()
            {
                Console.WriteLine("Hello2");
            }
      …

What is safe control in SharePoint 2010?

In SharePoint Environment a developer can add ASPX file very easily. An ASPX file contains code which may affect SharePoint environment. In simple word, there might be security risk of security injection.

To reduce the risk, SharePoint differentiate the assembly which need to protect against script injection. This can be done by marking a control as "Safe Control" in SharePoint web.config file.

Code snippet of Safe Control:

SharePoint>
     <SafeControls>
       <SafeControl Assembly="[Assembly Name]" Namespace="[Namespace]" TypeName="*" Safe="True" />
     </SafeControls>
</SharePoint>


To mark controls as safe or unsafe in the Package Designer
Create a SharePoint solution with a Visual Web Part project.Add two controls to the Web part: a text box and a button. Leave the names at their default values, TextBox1 and Button1, respectively.Take note of the namespace of the control because it is used later.On the menu …