// Passing By Output
// Passing by output is similar to Reference params. Except that Output params transmit data
// out of the method, not accept data in it. Passing by Output technic defined by "out" keyword.
// So you will use "out" keyword for this purpose.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace NewSandbox
{
class Program
{
static void YourMethod(out int x, out int y)
{
x = 4;
y = 6;
}
static void Main(string[] args)
{
int x, y;
YourMethod(out x, out y);
Console.WriteLine(x); //output will be 4
Console.WriteLine(y); //output will be 6
Console.ReadKey();
}
}
}
20 Şubat 2018 Salı
(2/3) Passing argument by Reference
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SoloLearn
{
class Program
{
static void YourMethod(ref int m)
{
m = m * m;
}
static void Main(string[] args)
{
int number = 5;
YourMethod(ref number); // Now the "number" variable has affected
Console.WriteLine(number); //output will be 25. NOT 5.
Console.ReadKey();
}
}
}
(1/3) Passing argument by Value
// 1) Passing By Value
// C# creates a copy of the given variable's value and put it
// into the method's parameter. Ergo you can do any changes you
// want on the parameter within the method without making any
// changes on the argument. I.e you are changing only the "Copy
// of the Argument's Value". Not given argument or argument's value.
// -By default, C# will use -By Value- technic to passing the arguments.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace NewSandbox
{
class Program
{
static void YourMethod(int m){
m = m*m;
}
static void Main(string[] args)
{
int number = 5;
YourMethod(number); //output will be 5
}
}
}
// Brief explanation: The method will operate on the VALUE, not the ACTUAL VARIABLE.
19 Şubat 2018 Pazartesi
Csharp'ta if - else if arasındaki fark -45
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
namespace _138_if_else_if_arasındaki_fark__45
{
class Program
{
static void Main(string[] args)
{
//Örnek 1
int theSayi = 3;
if (theSayi == 3)
{
Console.WriteLine("Sayı: " + theSayi);
}
if (theSayi == 4)
{
Console.WriteLine("Sayı: " + theSayi);
}
if (theSayi == 5)
{
Console.WriteLine("Sayı: " + theSayi);
}
if (theSayi == 6)
{
Console.WriteLine("Sayı: " + theSayi);
}
if (theSayi == 7)
{
Console.WriteLine("Sayı: " + theSayi);
}
/*
If metodunda: Yazdığın if metodu başarıyla çalışmışsa eğer;
yine de ileriki satırlarda bulunan if'ler de çalışır.
Else if konusunda durum farklıdır: Kullandığımız else if
satırlarının birini başarıyla çalıştırmışsak eğer; ileriki
satırlarda bulunan else if satırları yok yere okunmaz.
Örneğin theSayi == 3 olduğunu biliyor isek; artık sayının
4 veya 5 olmadığını biliyor oluruz. Bu yüzden ileriki
satırlarda "if" ile tekrar theSayi == 4 mü,
thesayi == 5 migibi sorguları yaparak programımızın
performansını düşürmemiş oluruz. Bu yüzden "else if" kullanırız
*/
//Örnek 2
int number = 3;
if (number == 444)
{
Console.WriteLine("Sayı: " + number);
}
else if (number == 4)
{
Console.WriteLine("Sayı: " + number);
}
else if (theSayi == 3)
{
Console.WriteLine("Sayı: " + number);
}
else if (theSayi == 6)
{
Console.WriteLine("Sayı: " + number);
}
else if (theSayi == 7)
{
Console.WriteLine("Sayı: " + number);
}
Console.ReadKey();
// Sonuç: Örnek 1 de tüm satırlar incelendi;
// Örnek 2 de; Başarıyla çalışan else if metodundan
// sonraki else if metodları yok yere çalışmamış oldu.
}
}
}
18 Şubat 2018 Pazar
Csharp'ta & ve && arası fark -44
&& : birinci kondüsyon False ise, ikinci kondüsyona bakılmayacaktır.. (Birinci False ise zaten if metodu çalışmayacağından, ikinci kondüsyonu incelemeye gerek yoktur.)
& : Birinci kondüsyon False olsa dahi, ikinci kondüsyon yine de incelenecektir.
Aynı durum, “veya” işaretlerimiz olan || ve | için de geçerlidir.
“Veya” işaretinde de Birinci kondüsyon True ise; ikincinin incelenmesi gerekmez. Bu yüzden yukarıdaki fikir aynı şekilde “veya” için de kullanılabilir.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication21
{
class Program
{
static void Main(string[] args)
{
string isim = "Ahmet";
int sayi = 4;
if (isim == "Ahmet" || sayi == 4)
{
Console.WriteLine("if metodu çalıştı.");
}
else
{
Console.WriteLine("if metodu ÇALIŞMADI");
}
Console.ReadKey();
}
}
}
Kaydol:
Kayıtlar (Atom)