|
class Program
{
public static void Calc(int a, int b, ref int x, ref int y, ref int z)
{
x = a + b;
y = a - b;
z = a * b;
}
static void Main(string[]
args)
{
int
p, q, sum, sub, mul;
p = 5;
q = 10;
sum = 0; // in case of ref we have to initialize
sub = 0; // variables whose reference is passing to
function
mul = 0; // before passing reference to function
Calc(p, q, ref
sum, ref sub, ref
mul);
Console.WriteLine("Sum: {0}", sum);
Console.WriteLine("Sub: {0}", sub);
Console.WriteLine("Mul: {0}", mul);
Console.ReadKey();
}
}
|
class Program
{
public static void Calc(int a, int b, out int x, out int y, out int z)
{
x = a + b; // we have to initialize in the
y = a - b; // function
z = a * b; //
}
static void Main(string[]
args)
{
int
p, q, sum, sub, mul;
p = 5;
q = 2;
//sum =
0; // in case of out we don't need to initialize
//sub =
0; // variables whose reference is passing to
function but
//mul =
0; // the calling function have to intialize that
reference
Calc(p, q, out
sum, out sub, out
mul);
Console.WriteLine("Sum: {0}", sum);
Console.WriteLine("Sub: {0}", sub);
Console.WriteLine("Mul: {0}", mul);
Console.ReadKey();
}
}
|
Get C#, ASP.NET, HTML, JavaScript, XML, WCF, Web services and Ajax tips.
menu
- Home
- Asp.Net
- MVC
-
C#
- Ref
- Constructor
- Constructor Program
- Jagged Array
- Command Line Argument
- Stack and Heap
- Ref and Out
- Const, ReadOnly and Static
- Generic
- Two Interfaces With Same Method Name
- Inheritance
- Is Keyword
- Custom List with OnAdd Event
- Data Annotation
- Covariance & Contravariance
- Signing - Strong vs Weak Reference
- Sorting List by IComparable vs IComparer
- WCF
- JavaScript
- SQL
- Others
- Contact
Thursday, August 16, 2012
Ref and Out
Stack and Heap
Stack is a memory
location where data type variables, reference type memory location and value
type data are stored.Command Line Argument in C Sharp
Jagged Array
Constructor in C Sharp
|
public class A
{
public
A()
{
Console.WriteLine("A");
}
}
public class B:A
{
public
B()
{
Console.WriteLine("B");
}
}
class Program
{
static void Main(string[]
args)
{
B
objB = new B();
Console.WriteLine("C");
Console.ReadKey();
}
}
|
public class
A
{
static
A() // this static constructor will called only once
{
Console.WriteLine("A");
}
public
A(int x)
{
Console.WriteLine("A1");
}
}
public class B : A
{
public
B():base(1)
{
Console.WriteLine("B");
}
}
class Program
{
static
void Main(string[]
args)
{
B
objB = new B();
Console.WriteLine("C");
Console.ReadKey();
}
}
|
|
public class B
{
private
B()
{
Console.WriteLine("B");
}
}
class Program
{
static
void Main(string[]
args)
{
B
objB = new B();
Console.WriteLine("C");
Console.ReadKey();
}
}
|
public class B
{
public
static B()
{
Console.WriteLine("B");
}
}
class Program
{
static
void Main(string[]
args)
{
B
objB = new B();
Console.WriteLine("C");
Console.ReadKey();
}
}
|
Thursday, July 7, 2011
Check All Check box in Grid View Control without Postback
<script type="text/javascript" language="javascript">
function checkAllBoxes(grid, num)
{
var totalChkBoxes = parseInt(num);
var gvControl = document.getElementById(grid);
var gvChkBoxControl = "chkBoxChild";
var mainChkBox = document.getElementById("chkBoxAll");
var inputTypes = gvControl.getElementsByTagName("input");
for(var i = 0; i < inputTypes.length; i++)
{
if(inputTypes[i].type == 'checkbox' && inputTypes[i].id.indexOf(gvChkBoxControl,0) >= 0)
inputTypes[i].checked = mainChkBox.checked;
}
}
</script>
<asp:GridView ID="grdDR" runat="server">
<Columns>
<asp:TemplateField>
<HeaderTemplate>
<input id="chkBoxAll" type="checkbox"
onclick="checkAllBoxes('<%= grdDR.ClientID %>', '<%= grdDR.Rows.Count %>')" />
</HeaderTemplate>
<ItemTemplate>
<asp:CheckBox ID="chkBoxChild" runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="Trns ID" HeaderText="Trns ID" >
<ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" />
</asp:BoundField>
<asp:BoundField DataField="User" HeaderText="User" >
<ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" />
</asp:BoundField>
<asp:BoundField DataField="Deposit Amount" HeaderText="Deposit Amount" >
<ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" />
</asp:BoundField>
Monday, May 23, 2011
Row Number in GridView
