You are on page 1of 17

:

@ .

1. Hello C#
C# , Hello C#.
1. Visual Studio.
2. : [File] [New] [Project].

3. [Visual C#] [Windows] [Console Application]


, HelloCSharp:

(softuni.org). CC-BY-NC-SA.
: . 1 17
4. Main(string[] args). () C#.
5. { }.
6. [Enter] {.

7. ( "Hello C#"):

Console.WriteLine("Hello C#");

{.

(softuni.org). CC-BY-NC-SA.
: . 2 17
8. [Ctrl+F5]. :

9. judge .
https://judge.softuni.bg/Contests/Practice/Index/150#0. .
Hello CSharp. Visual Studio
:

10. [Submit].
judge :

2. Expression
C# , :

(softuni.org). CC-BY-NC-SA.
: . 3 17
(3522 + 52353) * 23 - (2336 * 501 + 23432 - 6743) * 3

: ( Windows Calculator).
1. C# Expression.
2. static void Main(string[] args) { }.
3. ,
. Console.WriteLine():

4. [Ctrl+F5] :

5. judge : https://judge.softuni.bg/Contests/Practice/Index/150#1.

(softuni.org). CC-BY-NC-SA.
: . 4 17
3. 1 20
C# , 1 20 .
1. C# Nums1To20:

2. 20 Console.WriteLine(), , 1 20.

(softuni.org). CC-BY-NC-SA.
: . 5 17
3. judge :
https://judge.softuni.bg/Contests/Practice/Index/150#2
4. - , 20
? for loop C#.

4. 55
C# , 55 , 10 :

*
**
***
****
*****
******
*******
********
*********
**********
1. C# TriangleOf55Stars.
2. , , 10 ,
Console.WriteLine("*").
3. judge : https://judge.softuni.bg/Contests/Practice/Index/150#3.
4. , .
for ?

(softuni.org). CC-BY-NC-SA.
: . 6 17
5.
C# , a b,
a b. :

a b area
2 7 14
7 8 56
12 5 60
1. C# . , :

static void Main(string[] args)


{
var a = decimal.Parse(Console.ReadLine());
var b = decimal.Parse(Console.ReadLine());

// TODO: calculate the area and print it


}
2. -, .
3. judge : https://judge.softuni.bg/Contests/Practice/Index/150#4.

6. *
C# , N
N , -:


***
3 * *
***
****
* *
4
* *
****
*****
* *
5 * *
* *
*****
1. C# . N (2 N 100), :

static void Main(string[] args)


{
var n = int.Parse(Console.ReadLine());

// TODO: print the rectangle


}
2. -, , .
for-. .
3. judge : https://judge.softuni.bg/Contests/Practice/Index/150#5.

(softuni.org). CC-BY-NC-SA.
: . 7 17
: Web
7.
(GUI) , :

[Calculate]
.
, ,
(GUI) . (
, desktop apps) , :
, , , .
Windows Forms,
Windows Visual Studio C#.
1. Visual Studio C# Windows Forms Application:

2. Windows Forms ,
( ):

(softuni.org). CC-BY-NC-SA.
: . 8 17
3. (Toolbox) (TextBox), (Label)
(Button), . :

4. . Properties
(Name):

(softuni.org). CC-BY-NC-SA.
: . 9 17
: textBox1, textBox2, textBoxSum
: buttonCalculate
: FormCalculate
5. (Text ) :
buttonCalculate "Calculate"
label1 "+"
label2 "="
Form1 "Sumator"

6. , -:

(softuni.org). CC-BY-NC-SA.
: . 10 17
7. [Ctrl+F5]. , ,
.

8. ,
. [Calculate]. ,
:

9. C# { }, :

(softuni.org). CC-BY-NC-SA.
: . 11 17
var num1 = decimal.Parse(this.textBox1.Text);
var num2 = decimal.Parse(this.textBox2.Text);
var sum = num1 + num2;
textBoxSum.Text = sum.ToString();

textBox1 num1,
textBox2 num2, num1 + num2 sum
sum textBoxSum.

10. [Ctrl+F5] . 4 + 5.
-12.5 + 1.3:

11. , aaa bbb. :

12. . ,
. , :

private void buttonCalculate_Click(object sender, EventArgs e)


{
try

(softuni.org). CC-BY-NC-SA.
: . 12 17
{
var num1 = decimal.Parse(this.textBox1.Text);
var num2 = decimal.Parse(this.textBox2.Text);
var sum = num1 + num2;
textBoxSum.Text = sum.ToString();
}
catch (Exception)
{
textBoxSum.Text = "error";
}
}

( )
error .
13. [Ctrl+F5] .
error .

8.
, .
[Calculate]
. :

, ,
.
(URL) . ,
,
.

(softuni.org). CC-BY-NC-SA.
: . 13 17
ASP.NET MVC,
C# Visual Studio.
1. Visual Studio C# ASP.NET Web Application:

2. MVC:

3. Views\Home\Index.cshtml. (view)
:

(softuni.org). CC-BY-NC-SA.
: . 14 17
14. Index.chtml :

@{
ViewBag.Title = "Sumator";
}

<h2>Sumator</h2>

<form method="post" action="/home/calculate">


<input type="number" name="num1" value="@ViewBag.num1" />
<span>+</span>
<input type="number" name="num2" value="@ViewBag.num2" />
<span>=</span>
<input type="number" readonly="readonly" value="@ViewBag.sum" />
<input type="submit" value="Calculate" />
</form>

.
, ViewBag. ,
[Calculate] /home/calculate ( calculate home ).
4. Index.cshtml :

(softuni.org). CC-BY-NC-SA.
: . 15 17
15. (action), [Calculate].
Controllers\HomeController.cs
HomeController :

public ActionResult Calculate(int num1, int num2)


{
this.ViewBag.num1 = num1;
this.ViewBag.num2 = num2;
this.ViewBag.sum = num1 + num2;
return View("Index");
}

calculate. num1 num2


ViewBag, . ViewBag
,
.
5. HomeController.cs :

(softuni.org). CC-BY-NC-SA.
: . 16 17
6. . [Ctrl+F5] :

(softuni.org). CC-BY-NC-SA.
: . 17 17

You might also like