Showing posts with label apoorv parmar. Show all posts
Showing posts with label apoorv parmar. Show all posts

Thursday, 19 July 2012

Method inside structure

Method inside structure


using System;
public struct My_Details
{
public float f;
public string s;
public int i;
public void Sub()
{
Console.WriteLine("this method is for substraction");
}
}
class Sum
{
public static void Main()
{
My_Details m=new My_Details();
m.f=float.Parse(Console.ReadLine());
m.s="hi this is stiring data";
Console.WriteLine(m.s+m.f);
m.Sub();
}
}

Saturday, 14 July 2012

Music In C#

Music in C sharp






using System;
class Car
{
static void Main()
{
for(int i=37; i<=10000; i+=100)
{
Console.Beep(i,1000);
}
}
}
Content Powered By : 
 

Alternative Of Console Class

Alternative of Console class to use




using aditya=System.Console;
class car
{
public static void Main()
{
        aditya.WriteLine("Hi");
}
}

Content Powered By :

 

Wednesday, 11 July 2012

A Programme Without using "Using"

                             Without Using Keyword
After So many Classes Of working :

We learnt in the very first class that we need to use Namespace.
But can we make a C# programme without using the " USING " keyword .

Lets Have a Look :

                                                  "With Using"

using System;
class print
{
    public static void Main()
    {
        Console.WriteLine("Hello World");
       
    }
}


 
                                                     "Without Using"
class print
{
    public static void Main()
    {
        System.Console.WriteLine("Hello World");
       
    }
}


Input in Loop

Input in for loop


using System;
class abc
{
public static void Main()
{
int a,b;
Console.WriteLine("enter no b and a");
b=Convert.ToInt32(Console.ReadLine());
for(a=Convert.ToInt32(Console.ReadLine());a<=b;a++)
{
Console.WriteLine("hiu");
}
}
}

Taking Value In Command Line

Take value in Command Line parameter (input value on Excution Time)




using System;
class sum
{
public void add(int a, int b, string s)
{
int c=a+b;
Console.WriteLine("Result :"+c );
Console.WriteLine("Result : "+s);
}
public static void Main(string [] arg)
{
sum s = new sum();
s.add(Convert.ToInt32(arg[0]),  Convert.ToInt32(arg[1]), arg[2]);
       }

}



Tuesday, 10 July 2012

How To Copy Array

How to copy array ?

 using System;
class arr
{
public static void Main()
{
int [] a=new int[4];
a[0]=1;
a[1]=2;
a[2]=3;
a[3]=4;
int[] b=a;
Console.WriteLine("third index value of an array is :"+b[2]);
}
}


Here copy all index of array from a to b.

Instance Without A Class

Instance without class

To use var keyword you need .net framework 3.0 or latest than 3.0


using System;
using System.Linq;
class car
{ static int c;
public void Sum(int a, int b)
{
c=a+b;
Console.WriteLine("Sum is :"+c);
}
public static void Main()
{
var m=new car();
m.Sum(2, 4);
}
}

Eleventh Class

Eleventh Class (constructor and Destructor)

constructor and destructor in c sharp

constructor :
1. Same name as class name.
2. Constructor call automatically in Main().
3. No return type use to declare constructor.

Example of constructor


using System;
class car
{
car()
{
Console.WriteLine("Constructor Invoked");
}
public static void Main()
{
car c=new car();
}
}


Here car() is constructor and dont need to access it through object.

Two type of Constructor 


1. Instance constructor
2. Static constructor

1. Instance Constructor

Instance variable is use to instance data member of a class.
N number of constructor can be declare in a class.

Example of Instance Constructor



using System;
class car
{
int a, b, c;
car()
{
a=2;b=3;
c=a+b;
Console.WriteLine("Result is :"+c);
}
public static void Main()
{
car c = new car();
}
}

                                                 Example 2



using System;
class car
{
int a, b, c;
car()
{
a=2;b=3;
c=a+b;
Console.WriteLine("Result is :"+c);
}
public void color()
{
Console.WriteLine("hi this is red color");
}
public static void Main()
{
car c = new car();
c.color();
}
}


2. static constructor


static constructor is use to initialize the static variable of a class.



using System;
class cons
{
cons()
{
Console.WriteLine("this is first constructor");
}
static cons() //static constructor run at first...
{
Console.WriteLine("this is second constructor");
}
public static void Main()
{
cons c=new cons();
}
}

For Loop

          Some Example for ' for Loop '



Example no. 1


using System;

class Circle
{
public static void first()
        {
int a,b,c,d;
                Console.Write("Enter value:{0}");
d=Convert.ToInt32(Console.ReadLine());

for(a=1;a<=d;a++)
{
for(b=1;b<=d-a;b++)
{
Console.Write(" ");
}
for(c=1;c<=(2*a)-1;c++)
{
Console.Write("*");
}
       Console.WriteLine();
}             
  }
}

class Call
{
public static void Main()
{
Circle.first(); 

}
}

Example 2



using System;

class Circle
{
public static void first()
        {
int a,b,d;
                Console.Write("Enter value:{0}");
d=Convert.ToInt32(Console.ReadLine());

for(a=1;a<=d;a++)
{
for(b=1;b<=a;b++)
{
Console.Write("*");
}
       Console.WriteLine();
}
             
  }
}

class Call
{
public static void Main()
{
Circle.first();

}
}

Example 3:


using System;

class Circle
{
public static void first()
        {
int a,b,d;
                Console.Write("Enter value:{0}");
d=Convert.ToInt32(Console.ReadLine());
for(a=d;a>=1;a--)
{
for(b=1;b<=a;b++)
{
Console.Write("*");
}
       Console.WriteLine();
}
             
  }
}

class Call
{
public static void Main()
{
Circle.first();
}
}

Tenth Class

Tenth class (Array, foreach loop and command line parameter)

Array : its a reference type data type.
Define : An array is a collection of values of similar types.
store memory in Heap its bcaz reference type data type store in heap and value type data type store in stack.


1. Syntax
             datatype [] arrayname;
2. Declare
             int [] arr;


Here int is data type.
[] you can say it subscripts or index or Rank or Dimension


How to intialize an array ?


There are four type to initialize array


1.

int [] arr=new int[5];
arr[0]=2;
arr[1]=34;
arr[2]=22;
arr[3]=33;
arr[4]=55;



2.

int [] arr=new int [] {2, 34, 22, 33, 55};



3.

int [] arr = new int [] {2, 34, 22, 33, 55};




4.

int [] arr = {2, 34, 22, 33, 55};



Example 1:


using System;
class array
{
public static void Main()
{
int [] arr=new int[5];
arr[0]=2;
arr[1]=34;
arr[2]=22;
arr[3]=33;
arr[4]=55;
Console.WriteLine("Value of first index is "+arr[0]);
}
}

                                                          foreach Loop



Syntax    foreach(Data Type Name of variable in Name of variable)

Example foreach(string str in args)

Here 'in' is a keyword

Here transfer the all value from args to str


             Example of foreach and Command Line Parameter


Command Line Parameter



using System;
class Car
{
public static void Main(string [] args)
{
foreach(string str in args)
{
Console.WriteLine(str);
}
}
}



                            How to Copy array







using System;
class arr
{
public static void Main()
{
int [] a=new int[4];
a[0]=1;
a[1]=2;
a[2]=3;
a[3]=4;
int[] b=a;  //transfer all data of a to b.

               Console.WriteLine("third index value of an array is :"+b[2]);
}
}

BROUGHT TO YOU BY : www.hamarasem.com

Ninth Class (Test)

                             Ninth class Test

1. How many types of application in .net framework.
2. What is a program ?
3. What is a function ? With Example.
4. What is a variable ? with example.
5. What is a class ? with example.
6. What is namespace ? create a namespace and use it.
7. What is using ?
8. Why use a class keyword in c# ?
9. What is a Main() in c #  and its use.
10. What is a WriteLine() and its use in program.
11. How many types of operator in c# with name and operator symbol.
 Brought To You By :

Eighth Class (Name Space,Structure & Enumeration

Material of eighth class (user defined namespace, structure and Enumeration)

namespace : Its a collection classes and sub namespace.

two type of namespace
1. predefined namespace
2. user defined namespace


1. predefined namespace

which we use already defined that`s called predefined like System namespace.

2. user defined namespace

we can create our own namespace and can use functionality many times after making a namespace.

Example 1:


using System;
namespace Believe
{

class Func
{
static int  a, b, c;
public static void Sum()
{
                        // always method should be static
a=2;b=3;
c=a+b;

                        Console.WriteLine("Sum of two no is :"+c);
}
public static void Sub()
{
                        // always method should be static
a=2;b=3;
c=a-b;
Console.WriteLine("Sum of two no is :"+c);
}

}

}
class entry
{
public static void Main()
{
Believe.Func.Sum();
Believe.Func.Sub();
}
}

Structure Data type

Define : Hold different type of data type variable in a single structure variable.
its a value type data type.
use struct keyword to use structure.


using System;
struct book_details
{
public int Book_id;
public string Book_name;
public double Book_cost;
};
class Store
{
public static void Main()
{
book_details b=new book_details();
b.Book_id=1234;
b.Book_name="Dunya Infocom";
b.Book_cost=2003.22;
Console.WriteLine("Book ID is : "+b.Book_id);
Console.WriteLine("Book Name is : "+b.Book_name);
Console.WriteLine("Book cost is : "+b.Book_cost);
}
}

Structure cannot be default constructor. Here book_details() is not a constructor.

Enumeration Data type


use enum keyword to use enumeration
its a value type data type.
always start index at 0.

using System;
class enumeration
{
enum Days{sun, mon, tues, wed=10, thur, fri, sat};
public static void Main()
{
int nameoffirstdays= (int)Days.sun;
int nameoflastdays=(int)Days.sat;
Console.WriteLine("Name of first days : "+nameoffirstdays);
Console.WriteLine("Name of last days : "+nameoflastdays);
}
}

Output 

Seventh Class (Parameter)

Seventh class material (function with parameter, Instance Variable)

Function with parameter

public static void Main(string [] args)

This is called function with parameter, Here (string [] args) is called parameter.

'string' is Data type ' [] ' is array and 'args' is name of variable or name of array.

Example : 1


using System;
class arr
{
public void abc(int a, int b)
{
int c=a+b;
Console.WriteLine("Sum is : "+c);
}
public static void Main()
{
arr d=new arr();
d.abc(3, 5);
}
}

Instance Variable and instance function/method/behaviour



using System;
class Instance
{
int a, b, c;
public static void Main()
{
Instance i=new Instance();
i.a=2;   //we can declare here also like this    i.a=2;i.b=3;
i.b=3;
i.c=i.a+i.b;
Console.WriteLine("Result is : "+i.c);
}
}

Instance Function


using System;
class Instance
{
public void Roy()
{
      Console.WriteLine("this is Believe Techno");
}
public static void Main()
{
Instance i=new Instance();
i.Roy(); //it called instance function

}
}


Access Variable and Function without instance.


using System;
class roy
{
public static int a,b,c;
public static void believe()
{
Console.WriteLine("Hi static function");
}
public static void Main()
{


                believe();   //we dint need here to make object or instance..
a=3;b=4;
c=a+b;
Console.WriteLine("Result is :"+c);
}
}

Non static variable cannot access in non static function without instance but static variable can directly access to the static function.

Sixth Class ( Looping )

Sixth Class Material (Types of Looping concept)

There are four types of loops
1. for
2.while
3.do while
4.for each

1. for Loop


In for loop we declare three thing under for loop parameter
1. intialization
2.Termination or condition (always use comparison operator)
3.Increament or Decreament
Always have body for this loop

Like this

for(int a=0;  a<=10;  a++)
{
}

A simple program to use this loop.

Example 1.


using System;
class Loop
{
public static void Main()
{
for(int a=0; a<=100; a++)
{
Console.WriteLine(a);
}
}
}
Output : 0 to 100 no will be display

Example 2.


using System;
class Loop
{
public static void Main()
{
for(int a=2; a>=100; a++)
{
Console.WriteLine(a);
}
}
}
Output : Nothing will be display....body will be close bcaz 2 is less than 100 and cant excute under for loop body.

Example 3.


using System;
class Loop
{
public static void Main()
{
for(int a=2; a>=1; a++)
{
Console.WriteLine(a);
}
}
}
output : 0 to infinite to stop this excution on run time type ctrl+c

Example 4.

Make a simple table. Here we have to give a no for table and generate a table.


using System;
class Loop
{
public static void Main()
{
int b=1;
Console.Write("Enter any no to get Table : ");
b=Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Table of  "+b+" is : ");
for(int a=1; a<=10; a++)
{
int c=a*b;
Console.WriteLine(c);
}
}
}


Mystery about for loop


Example 1.



using System;
class Loop
{
public static void Main()
{


for(int i=0;i<10;i++);
Console.WriteLine(i);
}
}
Here output is error


Example 2.



using System;
class Loop
{
public static void Main()
{
int i;
for(i=0;i<10;i++);
Console.WriteLine(i);
}
}
output is 10

2. While loop


In while loop our for loop confusion remove and know our looping process in a good way.
Because there we dont know when our increament occur. increament doessn`t occur in a first time iteration.
thats occur from second time.
We will learn here in a good way what`s happening.

Using System
class Loop
{
public static void Main()
{
int i=0;
while(i<=5)
{
Console.WriteLine(i);
i++;
}
}
}
Output : 0 to 5

In this program we can know when intializing variable when terminating and also about increasing.

3. do while

do while loop is same as a do loop but differ is that
in while loop if condition is true than while body will be excute and if false than while body will be terminate but in do while loop 1 statement will be must display wheather statement is true or false.
always


using System;
class Loop
{
public static void Main()
{
int i=0;
do
{
Console.WriteLine(i);
i++;
}
while(i<10);
}
}
Output : 0 to 9

Monday, 9 July 2012

Compare five numbers

Compare five number which is greater ?


using System;
class Five
{
public static void Main()
{
int a, b,c,d,e;
Console.WriteLine("enter 1st no .");
a=Convert.ToInt32(Console.ReadLine());
Console.WriteLine("enter 2nd no .");
b=Convert.ToInt32(Console.ReadLine());
Console.WriteLine("enter 3rd no .");
c=Convert.ToInt32(Console.ReadLine());
Console.WriteLine("enter 4th no .");
d=Convert.ToInt32(Console.ReadLine());
Console.WriteLine("enter 5th no .");
e=Convert.ToInt32(Console.ReadLine());
if((a==b)||(a==c)||(a==d)||(a==e)||(b==c)||(b==d)||(b==e)||(c==d)||(c==e)||(d==e))
{
Console.WriteLine("ur some no are same enter differ no for comparison");
}
else if((a>b)&&(a>c)&&(a>d)&&(a>e))
{
Console.WriteLine("1st is greater than all no.");
}
else if((b>a)&&(b>c)&&(b>d)&&(b>e))
{
Console.WriteLine("2nd is greater than all no.");
}
else if((c>a)&&(c>b)&&(c>d)&&(c>e))
{
Console.WriteLine("3rd is greater than all no.");
}
else if((d>a)&&(d>b)&&(d>c)&&(d>e))
{
Console.WriteLine("4th is greater than all no.");
}
else
{
Console.WriteLine("5th is greater");
}
}
}

Fifth Class Material Operators

Fifth class Material (Operators in details)


1. Arithmatic operator                  :   +, - , * ,   / ,  %
2. Arithmatic assignment operator :   +=, -= , *= ,   /= ,  %=
3. Unary Operator                        :   ++, --
4. Comparison Operator               :   < , > , <=, >=, ==, !=
5. Logical Operator                       :   &&, ||, !

1. Arithmatic operator :

we have seen this operator...

2. Arithmatic assignment operator :

Example 1



using System;
class com
{
public static void Main()
{
int a=4, b=3;
a=+b;
Console.WriteLine("a is : "+a+" and "+"b is : "+b);
}
}
output is : a is 3 and b is 3


Example 2



using System;
class com
{
public static void Main()
{
int a=4, b=3;
a+=b;
Console.WriteLine("a is : "+a+" and "+"b is : "+b);
}
}
output is : a is 7 and b is 3


Example 3



using System;
class com
{
public static void Main()
{
int a=4, b=3;
a+=b;
b+=a;
Console.WriteLine("a is : "+a+" and "+"b is : "+b);
}
}

Simple Calculator

Make a simple calculator using operators.


using System;

class man
{
//dont ever take input from user in class body. it will occur error.

double a,b,result;
public void Accept()
{

Console.WriteLine("Enter 1st no");
a = Convert.ToDouble(Console.ReadLine());
Console.WriteLine("Enter 2nd no");
b = Convert.ToDouble(Console.ReadLine());

}
public void add()
{
result=a+b;
Console.WriteLine("addition is : "+result);
}
public void substract()
{
result=a-b;
Console.WriteLine("substraction is : "+result);
}
public void multiple()
{
result=a*b;
Console.WriteLine("multiple is : "+result);
}
public void devide()
{
result=a/b;
Console.WriteLine("division is : "+result);
}
}
class aditya

{
public static void Main()
{
man m=new man();
m.Accept();
m.add();
m.substract();
m.multiple();
m.devide();
}
}







Fourth Class (Operators)

fourth class material (Operators)

There are five types of operator in c sharp.
1. Arithmatic operator
2. Arithmatic assignment operator
3. Unary operator
4. Comparison Operator
5. Logical Operator

1. Arithmatic operator                  :   +, - , * ,   / ,  %
2. Arithmatic assignment operator :   +=, -= , *= ,   /= ,  %=
3. Unary Operator                        :   ++, --
4. Comparison Operator               :   < , > , <=, >=, ==, !=
5. Logical Operator                       :   &&, ||, !

1..Arithmatic operator : 
a=8, b=4, c;
c=a+b;
output is 12

a=2, b=4, c;
c=a-b;
output is 4


2. Arithmatic assignment operator 


a=4;
b=6;
a+=b;
output is 10 and contain value in 'a'.
here a+=b mean a=a+b;
a-=b;
output is -2


3. Unary Operator


a=2;
b=4;
a++;
output is 3 and contain value in 'a'
here a++ mean a+1.
++ mean increament by 1;
-- mean decreament by 1;

here is two type of unary operator first one is pre and 2nd one is post.
if we use unary operator in bafore value called pre and use after value called post.

a++ mean post increament.
++a mean pre increament.

a=++b;
here value of
a is a=5 and b=5;

a=b++;
than value of a 4 but b is 5;

a=--b;
here value of a is 3 and b= 3

a=b--;
value of a is 4 but b is 3.

4. Comparison Operator

comparison operator always checks expression and it use on if else condition

like if you have to compare 2 differ number which is greater.
Like This

using System;
class Compare
{
       public static void Main()
      {
                int a=4, b=5;
                if(a>b)
                {
                          Console.WriteLine("a is greter");
                }
                 else
                 {
                          Console.WriteLine("b is greter");
                 }
      }
}

5. Logical Operator


&&, ||, !

check more dan one condition
if you have to compare 3 numbers which is greater
In && both condition should be true than return true else false.
In || any one condition should be true than it will return true else false.
In ! both condition should be false than it will return true else false.


using System;
class Compare
{
       public static void Main()
      {
                int a=8, b=5, c=6;
                if((a>b)&&(a>c))
                {
                          Console.WriteLine("a is greter");
                }
                 else if((b>a)&&(b>c))
                 {
                          Console.WriteLine("b is greter");
                 }
                 else
                 {
                           Console.WriteLine("c is greter");
                  }
      }
}

Thanks To Support By : Hamara Sem

About Main Method

About Main method

We can Declare Main method four types in C sharp.
1. public static void Main()
2. public static void Main(string [] args ) or public static void Main(string args [])
3. static void Main()
4. static int main()

We cant declare Main method without static keyword.
we can make more than 1 Main method in c sharp.

Main method declaration
public static void Main()
 

here
'public' is access specifier.
'static' is keyword.
'void' is a return type.
'Main' is a method.

In c sharp Main() method is a entry point of Program.
without making a Main method we cant run our program.