battle programmers alliance

battle programming a forum for elite programmers with extreme will power to sharpen theire skills
 
HomeCalendarFAQSearchMemberlistUsergroupsRegisterLog in
Share | 
 

 visual studio c# fast tutorial

View previous topic View next topic Go down 
AuthorMessage
Moti Barski

avatar

Posts : 74
Join date : 2011-08-02

PostSubject: visual studio c# fast tutorial   Sat Apr 08, 2017 6:12 pm

this tutorial is
assuming you read the vb.net walkthroughs of the book battle programming :

DL visual studio latest version

c# jutsu :

1 hello world console app :
file, new project, from tree view select visual c#, windows desktop, console application
the code placed in the main methode will be run :
type cw tab tab
Console.WriteLine("hello world");
Console.ReadKey();
// comment
press f5 to debug (run the program)
right click the now visible promt window, properties to change the font and stuff
shift + f5 : stop debugging
ctrl + f5 run without debugging , causes the app to pause
before closing

2 wpf
file, new project, from tree view select visual c#, windows desktop, WPF application
(similar to a win form, but looks more expensive) notice in the solution window the .cs file
is were you code cs = c# sharp

3 obj = null; //obj will be garbage collectet

4 namespace contain classes and are defined by code.
system.math // system = namespace, math = class
using Sytem.Math;

double pi = math.PI; // a field
double rounded = math.Round(pi, 2); // a methode
// static methode : used by the class without neccesarily using a created variable of the class type

6 import statements in vb tranlates to using

7 declaring variables :
int N = 0;
int yii = new int32(); // default 0
short n3 = -32768; // min -32768 max 32767
ushort n4 = 33767; // min 0 max 32767
uint n5 = 4;
const int N = 50;
object o1 = new Object();
string s1 = "hello"; // s1[1] contains 'e'
System.String s1 = "hello";
var implicitValue = 98; // set to int32
var implicitValue = 98L; // set to int 64
bool defaultBool = new boolean(); // false value
const int SomeNum = 42;
public const int SomeNum = 42; // available to the whole application as a class member

byte bul = 255;
bul++ // adds 1 therefore set to 0

char c1 = 'a';
char c2 = '\u0061'; // sets c2 to a
char.IsLetterOrDigit(('#')); // returns false

Datetime dt = new DateTime(1955, 1, 1);
Console.WriteLine("the date is: " + dt.ToString("M/d/yyyy")); // mask
Console.ReadKey();
Console.WriteLine("the date is: " + dt.ToString("MMMM d, yyyy")); // mask2
Console.ReadKey();

Datetime now = DateTime.Now;


8 multifunction summon example:
using System.text;

StringBuilder builder = new StringBuilder(); // more efficient string user
builder.Append("hello")
.Append(" ")
.Append("world");

9 comment out code : mark select code, edit, advanced, comment selection

10 opperators :
+,-,*,/ divide,% reminder
++,-- add, decrease by 1 : intvalue++;
+=, -= add, decrease from value : value += 5;
Equality (boolean) operators :
== equals x == y, != not equals, ! negation (not) : !x x is boolean variable
conditional operators :
&& and, || or, ?? null-coalescing : int new = (x ?? var2); returns x if
it has some value else return var2
relational and type testing :
<,>,<=,>=, is : type compatible : if (x is String)
Non-Case-Sensitive comparison :
if (string1.Equals(string2,StringComparison.OrdianlIgnoreCase))
{
}

11 refactor :
right click a marked variable , refactor, applies the change all over the code

12 conditionals
if true
{
}
else if (true)
{}
else
{
}

select case :
switch (variable)
{
case "+" ;
// code for case
break;
default; // case else
break;
}

13 full screen editor :
alt + shift + enter

14 looping

type for tab twice
for (int i = 0; i < length; i++)
{

}

while boolVariable
{
Console.WriteLine("lup");
}

for each loop snipet sample :
string[] fruit = {"apples", "oranges", "grapes"};
foreach (var item in fruit) // fruit is a collection variable
{
Console.WriteLine(item);
}

15 methodes :
static int Add(int value1, int value2) // static mean you can use it without
// an instace object of the class, see static summon
{
return value1 + value2;
}
static summon example :
int total = add(10, 30);

static void addToOut param(int value1,int value2, out int result) // void
// means the methode returns nothing, out is like vb.net byref
{
result = value1 + value2;
}

access identifier :
static int localField = 10; // var is accesable by the class
static public localField = 10; // var is accesable by everybody
static private localField = 10; // var is accesable only to the class

16 break; // jump out of code block (like a for loop)
continue; // go from here to the start of this code block

17 comment out marked code block : ctrl + k, then ctrl + c
comment in : ctrl + k, ctrl + u

18 go to methode's code, be on methode call code line , f12

19A debug tricks :
above problematic value type :
Debug.WriteLine("value of var1 :" + var1);
run in debug mode shift + f5
press ctrl + alt + o
to see an output window of said variable.

B make a breakpoint conditional :
in the output window breakpoint (now targeting your selected
breakpoint, right click, condition, type : var1==3 (for example)

C wrapping the code
try {} // code hya
catch (Exception)
{
//throw;
}

or
catch (Exception ex)
{Console.WriteLine(ex.message);}
finally{} // place code to run anyways after the final catch

20 array
sring[] fruit = { "apples" ," "oranges", "bananas" };

string[] names = new string[3];
names[0] = "naruto";
names[1] = "sasuke";
names[2] = "kabuto";

int[] weights = { 12, 34, 20, 23}
int sum = weights.sum();

string[,] grid = new string[5,5]; //2d array

21 List

var fruitList = new list<string>();
fruit
list.add("orange");

fruitList.sort();
foreach (var item in fruitList)
{
console.writeline(item);
}


static void Figs(list<string> items)
{
string figReport = iteems.contains("fig", stringcomparer.OrdinalIgnoreCase) ?
"yes there are":
"none";
console.writeLine(figReport);
}

22 DICTIONARY

var inventory = new Dictionary<string,double>();
var keys = inventory.keys; //behaves as list
console.WriteLine(keys.count);
foreach (var key in keys)
{
console.writeLine(inventory[key]); //value in dictionary assosiated to the key
}

string[] keysArray = keys.ToArray();
Array.sort(keysArray);
foreach (var key in keysArray)
{
console.writeLine(inventory[key]);
}

if (inventory.TryGetValue("figs", out value))
{
console.writeLine(value);
}
else
{
console.writeLine("figs not in inventory");
}

23 classes :
right click solution, add class

shared function addy(byval y as integer, ByVal x As integer) As Decimal
return x + y
End Function ' in vb.net =

public static decimal addy(int y, int x)
{
return x + y;
} ' in c#

calling the function from the main class :
className.addy(1,3);


class fruit
{
public string name; // right click var name, refactor, encapsulate field, apply :
}
turns to :

class fruit
{
private string name;
public string name
{
get { return name; }
set { name = value; }
}
}
another way :
public int Quantity { get; set; }
in the main class :
var fruit1 = new fruit();
fruit1.name = "guyava";

object in list reference :
var produce = new List<object>();
produce.Add(new fruit());
((fruit)produce[1]).name = "melon

override methode example :
public override string Tostring()
{return name + "bla bla";}

24 namespace :
wrap your added classes with
namespace namehere
{}
in your main code add using namehere; at the very start
or call classname.methodename() mark it and click ctrl + .

25 inheritance :
class name : motherclass {
public name (string name1, double weight) :
base(name1,weight) ' uses base class constructor
}

c# Special codes

1 new line :
Environment.NewLine

2 returning code to standard appearance : control + k , control + d
3 string + char : concates them

Back to top Go down
View user profile
 
visual studio c# fast tutorial
View previous topic View next topic Back to top 
Page 1 of 1
 Similar topics
-
» Setting Up Webdriver in Visual Studio
» making a selenium framework in eclipse(java environment). previously used visual studio.
» c# webdriver - Data Driven : DataSource attribute error - Connecting Automation with MTM
» Visual aura seems to be repeating over and over...this is new!
» Yet another new visual aura

Permissions in this forum:You cannot reply to topics in this forum
battle programmers alliance :: battle programming alliance :: battle programming-
Jump to: