Jump to content

Welcome to Geeks to Go - Register now for FREE

Need help with your computer or device? Want to learn new tech skills? You're in the right place!
Geeks to Go is a friendly community of tech experts who can solve any problem you have. Just create a free account and post your question. Our volunteers will reply quickly and guide you through the steps. Don't let tech troubles stop you. Join Geeks to Go now and get the support you need!

How it Works Create Account
Photo

forBeginners


  • Please log in to reply

#1
BuRnEr

BuRnEr

    Member

  • Member
  • PipPip
  • 48 posts
First there is a FQA?
can we use pointers in C# yes we can:

usafe compaling in C#
if you are using Visual Studio .Net you have to configure it:
like doing so;

Projects->c# project properties->Configuration properties->Allow Unsafe Code Blocks->TRue

and we can use pointers in C# now
how :?
there is only one different thing than C++ using keyword "unsafe"...

ExP:

using System;

class UsingPointerInCSharp{

static void Main(){
int number=30;
int *Num=&number;

Console.Writeline("The number is {0} and pointer Num is {1}",number,*Num);
}
}



using if statements:

using System;

class ifStatement{

static void Main(){
char answer;

Console.Write("How do you feel today y/n:");
Console.ReadLine();
if(answer=='y')
{
Console.WriteLine("...I am On Top Of World...");
}else{
Console.WriteLine("...I feel tired...");
}
}
}

or we can have more than one statements:Like

using System;

class manyifStatements{

static void Main(){
int number;
Console.Write("Enter Any number between 0-100:");
number=int.Parse(Console.ReadLine());

if(number<10)
Console.WriteLine("The number you entered "+number);
else if(number>10 && number<20)//&& meaning and
Console.WriteLine("The number you entered "+number);
else if(number>20&&number<30)
Console.WriteLine("The number you entered "+number);
else if(number>30&&number<40)
Console.WriteLine("The number you entered "+number);
else if(number>40&&number<50)
Console.WriteLine("The number you entered "+number);
else
Console.WriteLine("The number you entered "+number+" between 50 and 100");
}
}

or we have another way to do samething with switch statements :


using System;

class switchExample{

static int Main(){

int number;
Console.Write("Enter Any number between 1-5:");
number=int.Parse(Console.ReadLine());

switch(number)
{
case 1:
Console.WriteLine("Your Number is "+number);//if you enter 1
break;
case 2:
Console.WriteLine("Your Number is "+number);//if you enter 2
break;
case 3:
Console.WriteLine("Your Number is "+number);//if you enter 3
case 4:
Console.WriteLine("Your Number is "+number);//if you enter 4
break;
case 5:
Console.WriteLine("Your Number is "+number);//if you enter 5
break;

default:
Console.WriteLine("Your Number is "+number);//if you enter other numbers
break;
}
return 0;

}
}

how about loops? we use loops for avoiding sequentialy writing codes again and over again.
first type loop: before run the loop it checks the statement.
while....do


using System;

class WhileDoLoop
{
static void Main()
{
int Number = 0;
string MyName;
Console.Write("Enter your Name:");
MyName=Console.ReadLine();

while( Number <= 10 )
{
Console.WriteLine(Number+".");
Console.Write(MyName);
Number++;
}

Console.WriteLine();
}
}//when you run the code it produces 11 times your name 0 to 10

second type loop:this type loops first run the loop and than checks the statement
do...while

using System;

class doWhileLoop
{
static void Main()
{
int Number = 0;
string MyName;
Console.Write("Enter your Name:");
MyName=Console.ReadLine();

do {
Console.Write(Number+".");
Console.WriteLine(MyName);
Number++;
}while( Number <= 10 );

Console.WriteLine();
}
}

third type loop:we usually use this kind of loop counting number of items.like arrays
for...

using System;

class forLoop
{
static void Main()
{
for(int Counter = 0; Counter <= 12; Counter++)
{
Console.Write("The Counter is:");
Console.WriteLine(Counter);
}

Console.WriteLine();
}
}


and final loop:like for loop
foreach......

using System;

class forEachLoop
{ static void Main()
{
string MyName;
Console.Write("Enter Your Full Name:");
MyName=Console.ReadLine();
foreach(char letter in MyName)
{
int counter=1;
Console.WriteLine(counter+".\t"+letter);
counter++;
}
}
}//everything is threaded character by character and they assigned one by one to letter variable.

and last thing is that i want to mention enums are like class and struct, they let us to define new type. java doesnot supported, they are orginaly found in C++
and C# supports enums tooo
in my definition C#=java + C++(not all) so that means C# is a portable, powerfull and great programming language.because it takes future of java and C++
i recomend that who are new about programming just start with C#.

using System;

class enumExample
{
enum Employee
{
PartTime,
FullTime,
Contract,
Commission
}
static void Main()
{
string answer="y";
int type;
Console.WriteLine("0-Part Time");
Console.WriteLine("1-Full Time");
Console.WriteLine("2-Contractor");
Console.WriteLine("3-Commission");

while(answer!="n"){
Console.Write("Enter Employe type 0-3:");
type=int.Parse(Console.ReadLine());

switch((Employee)type)
{
case Employee.PartTime:

Console.WriteLine("Employee, No Benefits, No Vacation Payment");
break;
case Employee.FullTime:

Console.WriteLine("Employee, Full Benefits, Flat Salary $5000000,....:tazz:");
break;
case Employee.Contract:

Console.WriteLine("Employee, No benefits, hourly payment");
break;
case Employee.Commission:

Console.WriteLine("Employee, Commission Worker");
break;
default:
Console.WriteLine("Employee type Not Specify");
break;
}
Console.Write("\nEnter your answer to continue(y) or exit(n):");
answer=Console.ReadLine();

}
}
}


i have bad programming stile why?because i never use comments... bad habit.But i recomend that if you are really thinking about programming, you always use comments.. and it makes you more stronger programmer( i am not but you can) do it.Always Follow masters and create your own stile,...that makes you to be creative person....this all codes working but instead copy and past you do it manualy.By the time your fingers get more filexible, believe using keyboard important too
if you dont use your fingers well(if they dont dans on keyboard) i sugges you to get one typing tuto and start it rightaway.However it is boring but you ll get pay back.
And please dont message me individually because i have no time to reply it back.And that time i feel so bad can not replay back.Please just post
your messages to forum...

oop oop oop oop learn programming that way oop

0.001232 192.61.255.2 192.158.255.61 TCP telnet >3722 [SYN, ACK] seq=3044686613 Ack=3760483891 win=64240


BuRnEr
  • 0

Advertisements







Similar Topics

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

As Featured On:

Microsoft Yahoo BBC MSN PC Magazine Washington Post HP