TechAstro

Sunday, May 13, 2012

All about "out" and "ref"


5down vote



[ref] and [out] both allow the called method to modify a parameter. The difference between them is what happens before you make the call.

[ref] means that the parameter has a value on it before going into the function. The called function can read and or change the value any time. The parameter goes in, then comes out


[out] means that the parameter has no official value before going into the function. The called function must initialize it. The parameter only goes out


Here's my favorite way to look at it: [ref] is to pass variables by reference. [out] is to declare a secondary return value for the function. It's like if you could write this:
// This is not C#
public (bool, string) GetWebThing(string name, [ref] Buffer paramBuffer);

// This is C#
public bool GetWebThing(string name, [ref] Buffer paramBuffer, [out] string actualUrl);

Here's a more detailed list of the effects of each alternative:

Before calling the method:

[ref]: The called must set the value of the parameter before passing it to the called method.

[out]: The caller method is not required to set the value of the argument before calling the method. Most likely, you shouldn't. In fact, any current value is discarded.

During the call:

[ref]: The called method can read the argument at any time.

[out]: The called method must initialize the parameter before reading it.

Remoted calls:

[ref]: The current value is marshalled to the remote call. Extra performance cost.

[out]: Nothing is passed to the remote call. Faster.

Technically speaking, you could use always [ref] in place of [out], but [out] allows you to be more precise about the meaning of the argument, and sometimes it can be a lot more efficient.
Recently I am inspired by the show Satyamev Jayate by Aamir Khan I salute to Aamir for such a brilliant and brain storming idea or you can say it a social revolution and awakening which must go on and on for ever so that we and coming generations can be a part of it and share their views and ideas to hone this axe so that it can cut these abuses being part of our society.

Monday, September 13, 2010

Grouping data

1.)http://pratchev.blogspot.com/2008/03/grouping-with-rownumber.html

2.)http://download.cnet.com/Export-Query-to-Excel-for-SQL-Server/3000-10254_4-10604504.html

Wednesday, June 23, 2010

The Concept of pure object oriented Language

There are following pointswhich need tobe fulfilled by a pureobject oriented language:-

1. C++ allows writing global functions, outside of any class,
while in C# and Java all methods (functions) must be
included in a class.

2. According to "Pure" object oriented principle, no
method/routine should exist without the object. In C++, main
() method can be independant and does not need any class
but Java/C# its static method of "some" class.

3. C++ provides "Friends" which is absolute corruption to
the OO-Principle of encapsulation.

4. According OO-Principle, everything needs to be object.
C++ provide inbuilt datatype- int,float etc which are not
object in their nature. C#/Java also provides same kind of
datatype but its inner presentation is always object. For
example: in java you have got wrapper classes and in C#,
all these types are derived from System.ValueType object.

5. According OO-Principle, one object should have only one
hierarchical parent reference. In C++, Multiple-Inheritance
contradicts this principle.

Friday, May 28, 2010

Latest interview questions with answers

Hi all techies,


After a long gap i am back with some innovations and maverick concept just wait and watch for new updates.

Advance dotnet questions and answers

Q1:What is the difference between WCF and web service?

Answer:Asp.net web services are homogenous.
Asp.net web services can use only HTTP chanenel.
Not supports msmq and tcp binding...

WCF is flexible because its services can be hosted in
different types of applications. The following lists
several common scenarios for hosting WCF services:
IIS
WAS
Self-hosting
Managed Windows Service

WCF = Web services + .Net Remoting + MSMQ + (COM+)

Q2:Can we use WPF in web application?

Ans:No, we can't use WPF in web applicatons but we can use Silverlight cos WPF is for pure windows based application.

Wednesday, April 23, 2008

Constructor Execution see the difference

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace TestConstructorSeq
{
class Program
{
public class A
{
public A()
{
Console.WriteLine("I am A");
}
static A()
{
Console.WriteLine("I am static A");
}

}
public class B:A
{
public B()
{
Console.WriteLine("I am B");
}
static B()
{
Console.WriteLine("I am static B");
}

}

static void Main(string[] args)
{
B b = new B(); //This outputs
//I am Static B
Console.ReadLine(); //I am Static A
} //I am A
//I am B
}
}
=================================================================================
But this static constructor execution pattern changes in this 3 level inheritance
=================================================================================
class Program

{
public Program()
{
Console.WriteLine("I am p");

}

static Program()
{
Console.WriteLine("I am sp");

}

class Program1:Program

{
public Program1()
{
Console.WriteLine("I am p1");

}

static Program1()
{
Console.WriteLine("I am sp1");

}


}

class Program2 : Program1
{
public Program2()
{
Console.WriteLine("I am p2");

}

static Program2()

{
Console.WriteLine("I am sp2");

}

}

static void Main(string[] args)
{

Program2 p2 = new Program2();
Console.ReadLine();
}
}
}

//Check out the difference between the two

Dynamic Binding with datahiding query

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.FrameWork;


namespace DynamicBindingWithHiding
{
class A
{
public virtual void Whoareyou()
{
Console.WriteLine("I am in A");
Console.ReadLine();
}

}
class B:A
{
public override void Whoareyou()
{
Console.WriteLine("I am in B");
Console.ReadLine();
}

}
class C : B
{
public new virtual void Whoareyou()
{
Console.WriteLine("I am in C");
Console.ReadLine();
}

}
class D : C
{
public override void Whoareyou()
{
Console.WriteLine("I am in D");
Console.ReadLine();
}

}



class Program
{
static void Main(string[] args)
{
//C c = new D();
//c.Whoareyou();

A a = new D();
a.Whoareyou(); //It shows "I am in B" how?

}
}
}