Skip to content

Commit 2576dcc

Browse files
Merge pull request #5 from ferronicardoso/feature/new-posts
Feature/new posts
2 parents ac57e56 + 720abfc commit 2576dcc

File tree

3 files changed

+363
-2
lines changed

3 files changed

+363
-2
lines changed

.gitignore

Lines changed: 223 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,223 @@
1+
# Created by https://www.toptal.com/developers/gitignore/api/ruby,jekyll,jetbrains+all,rails
2+
# Edit at https://www.toptal.com/developers/gitignore?templates=ruby,jekyll,jetbrains+all,rails
3+
4+
### Jekyll ###
5+
_site/
6+
.sass-cache/
7+
.jekyll-cache/
8+
.jekyll-metadata
9+
# Ignore folders generated by Bundler
10+
.bundle/
11+
vendor/
12+
13+
### JetBrains+all ###
14+
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider
15+
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
16+
17+
# User-specific stuff
18+
.idea/**/workspace.xml
19+
.idea/**/tasks.xml
20+
.idea/**/usage.statistics.xml
21+
.idea/**/dictionaries
22+
.idea/**/shelf
23+
24+
# AWS User-specific
25+
.idea/**/aws.xml
26+
27+
# Generated files
28+
.idea/**/contentModel.xml
29+
30+
# Sensitive or high-churn files
31+
.idea/**/dataSources/
32+
.idea/**/dataSources.ids
33+
.idea/**/dataSources.local.xml
34+
.idea/**/sqlDataSources.xml
35+
.idea/**/dynamic.xml
36+
.idea/**/uiDesigner.xml
37+
.idea/**/dbnavigator.xml
38+
39+
# Gradle
40+
.idea/**/gradle.xml
41+
.idea/**/libraries
42+
43+
# Gradle and Maven with auto-import
44+
# When using Gradle or Maven with auto-import, you should exclude module files,
45+
# since they will be recreated, and may cause churn. Uncomment if using
46+
# auto-import.
47+
# .idea/artifacts
48+
# .idea/compiler.xml
49+
# .idea/jarRepositories.xml
50+
# .idea/modules.xml
51+
# .idea/*.iml
52+
# .idea/modules
53+
# *.iml
54+
# *.ipr
55+
56+
# CMake
57+
cmake-build-*/
58+
59+
# Mongo Explorer plugin
60+
.idea/**/mongoSettings.xml
61+
62+
# File-based project format
63+
*.iws
64+
65+
# IntelliJ
66+
out/
67+
68+
# mpeltonen/sbt-idea plugin
69+
.idea_modules/
70+
71+
# JIRA plugin
72+
atlassian-ide-plugin.xml
73+
74+
# Cursive Clojure plugin
75+
.idea/replstate.xml
76+
77+
# SonarLint plugin
78+
.idea/sonarlint/
79+
80+
# Crashlytics plugin (for Android Studio and IntelliJ)
81+
com_crashlytics_export_strings.xml
82+
crashlytics.properties
83+
crashlytics-build.properties
84+
fabric.properties
85+
86+
# Editor-based Rest Client
87+
.idea/httpRequests
88+
89+
# Android studio 3.1+ serialized cache file
90+
.idea/caches/build_file_checksums.ser
91+
92+
### JetBrains+all Patch ###
93+
# Ignore everything but code style settings and run configurations
94+
# that are supposed to be shared within teams.
95+
96+
.idea/*
97+
98+
!.idea/codeStyles
99+
!.idea/runConfigurations
100+
101+
### Rails ###
102+
*.rbc
103+
capybara-*.html
104+
.rspec
105+
/db/*.sqlite3
106+
/db/*.sqlite3-journal
107+
/db/*.sqlite3-[0-9]*
108+
/public/system
109+
/coverage/
110+
/spec/tmp
111+
*.orig
112+
rerun.txt
113+
pickle-email-*.html
114+
115+
# Ignore all logfiles and tempfiles.
116+
/log/*
117+
/tmp/*
118+
!/log/.keep
119+
!/tmp/.keep
120+
121+
# TODO Comment out this rule if you are OK with secrets being uploaded to the repo
122+
config/initializers/secret_token.rb
123+
config/master.key
124+
125+
# Only include if you have production secrets in this file, which is no longer a Rails default
126+
# config/secrets.yml
127+
128+
# dotenv, dotenv-rails
129+
# TODO Comment out these rules if environment variables can be committed
130+
.env
131+
.env*.local
132+
133+
## Environment normalization:
134+
/.bundle
135+
/vendor/bundle
136+
137+
# these should all be checked in to normalize the environment:
138+
# Gemfile.lock, .ruby-version, .ruby-gemset
139+
140+
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
141+
.rvmrc
142+
143+
# if using bower-rails ignore default bower_components path bower.json files
144+
/vendor/assets/bower_components
145+
*.bowerrc
146+
bower.json
147+
148+
# Ignore pow environment settings
149+
.powenv
150+
151+
# Ignore Byebug command history file.
152+
.byebug_history
153+
154+
# Ignore node_modules
155+
node_modules/
156+
157+
# Ignore precompiled javascript packs
158+
/public/packs
159+
/public/packs-test
160+
/public/assets
161+
162+
# Ignore yarn files
163+
/yarn-error.log
164+
yarn-debug.log*
165+
.yarn-integrity
166+
167+
# Ignore uploaded files in development
168+
/storage/*
169+
!/storage/.keep
170+
/public/uploads
171+
172+
### Ruby ###
173+
*.gem
174+
/.config
175+
/InstalledFiles
176+
/pkg/
177+
/spec/reports/
178+
/spec/examples.txt
179+
/test/tmp/
180+
/test/version_tmp/
181+
/tmp/
182+
183+
# Used by dotenv library to load environment variables.
184+
# .env
185+
186+
# Ignore Byebug command history file.
187+
188+
## Specific to RubyMotion:
189+
.dat*
190+
.repl_history
191+
build/
192+
*.bridgesupport
193+
build-iPhoneOS/
194+
build-iPhoneSimulator/
195+
196+
## Specific to RubyMotion (use of CocoaPods):
197+
#
198+
# We recommend against adding the Pods directory to your .gitignore. However
199+
# you should judge for yourself, the pros and cons are mentioned at:
200+
# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
201+
# vendor/Pods/
202+
203+
## Documentation cache and generated files:
204+
/.yardoc/
205+
/_yardoc/
206+
/doc/
207+
/rdoc/
208+
209+
/.bundle/
210+
/lib/bundler/man/
211+
212+
# for a library or gem, you might want to ignore these files since the code is
213+
# intended to run in multiple environments; otherwise, check them in:
214+
# Gemfile.lock
215+
# .ruby-version
216+
# .ruby-gemset
217+
218+
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
219+
220+
# Used by RuboCop. Remote config files pulled in from inherit_from directive.
221+
# .rubocop-https?--*
222+
223+
# End of https://www.toptal.com/developers/gitignore/api/ruby,jekyll,jetbrains+all,rails

README.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,4 @@ bundle exec jekyll serve
3838

3939
- [Jekyll • Simple, blog-aware, static sites](https://jekyllrb.com/)
4040

41-
-
42-
4341

Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
---
2+
title: 'Aprender a programar em C# – Parte 5'
3+
date: Thu, 18 Sep 2024 19:30:00 +0000
4+
draft: false
5+
tags: ['Aprender a programar em C#', 'C Sharp', 'C#','linq', 'lambda', 'Conceitos básicos', 'Iniciante', 'Visual Studio']
6+
---
7+
Na continuidade da nossa série sobre programação em C#, chegamos a um tema muito relevante e atual: LINQ (Language Integrated Query) e Expressões Lambda. Esses conceitos são fundamentais para quem deseja trabalhar com manipulação de dados de forma eficiente e expressiva. Neste artigo, vamos explorar o que são, como funcionam e como podemos utilizá-los em nossos projetos.
8+
9+
## 1. O que é LINQ?
10+
11+
LINQ é uma poderosa ferramenta que permite realizar consultas em coleções de dados de forma semelhante a consultas SQL, mas diretamente em C#. Com LINQ, você pode trabalhar com arrays, listas, bancos de dados e XML, entre outros, utilizando uma sintaxe clara e concisa.
12+
13+
### 1.1. Tipos de LINQ
14+
15+
Existem diferentes tipos de LINQ que podemos utilizar:
16+
17+
- **LINQ to Objects**: Permite realizar consultas em coleções em memória, como arrays e listas.
18+
- **LINQ to SQL**: Permite realizar consultas em bancos de dados SQL Server.
19+
- **LINQ to XML**: Permite realizar consultas em documentos XML.
20+
21+
## 2. Sintaxe do LINQ
22+
23+
A sintaxe do LINQ pode ser dividida em duas abordagens: **Sintaxe de Consulta** e **Sintaxe de Método**.
24+
25+
### 2.1. Sintaxe de Consulta
26+
27+
A sintaxe de consulta é semelhante à SQL e é bastante intuitiva. Veja um exemplo:
28+
29+
```csharp
30+
using System;
31+
using System.Collections.Generic;
32+
using System.Linq;
33+
34+
class Program
35+
{
36+
static void Main()
37+
{
38+
List<int> numeros = new List<int> { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
39+
var pares = from n in numeros
40+
where n % 2 == 0
41+
select n;
42+
Console.WriteLine("Números pares:");
43+
foreach (var numero in pares)
44+
{
45+
Console.WriteLine(numero);
46+
}
47+
}
48+
}
49+
```
50+
51+
### 2.2. Sintaxe de Método
52+
53+
A sintaxe de método utiliza métodos de extensão e é mais comum em cenários onde você precisa de operações mais complexas. Veja o mesmo exemplo utilizando a sintaxe de método:
54+
55+
```csharp
56+
using System;
57+
using System.Collections.Generic;
58+
using System.Linq;
59+
60+
class Program
61+
{
62+
static void Main()
63+
{
64+
List<int> numeros = new List<int> { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
65+
var pares = numeros.Where(n => n % 2 == 0);
66+
Console.WriteLine("Números pares:");
67+
foreach (var numero in pares)
68+
{
69+
Console.WriteLine(numero);
70+
}
71+
}
72+
}
73+
```
74+
75+
## 3. O que são Expressões Lambda?
76+
77+
Expressões Lambda são uma forma concisa de representar métodos anônimos. Elas são frequentemente usadas em LINQ para definir critérios de seleção, filtragem e transformação de dados.
78+
79+
### 3.1. Sintaxe de Expressões Lambda
80+
81+
A sintaxe básica de uma expressão lambda é:
82+
83+
```csharp
84+
(parameters) => expression
85+
```
86+
87+
Por exemplo, a expressão lambda `n => n % 2 == 0recebe um parâmetro `ne retorna um valor booleano indicando se `n` é par.
88+
89+
## 4. Usando LINQ e Expressões Lambda Juntos
90+
91+
Uma das grandes vantagens de LINQ é que ele permite o uso de expressões lambda para realizar operações de forma mais flexível. Veja um exemplo onde utilizamos LINQ com expressões lambda para filtrar e ordenar uma lista de objetos:
92+
93+
```csharp
94+
using System;
95+
using System.Collections.Generic;
96+
using System.Linq;
97+
class Pessoa
98+
{
99+
public string Nome { get; set; }
100+
public int Idade { get; set; }
101+
}
102+
103+
class Program
104+
{
105+
static void Main()
106+
{
107+
List<Pessoa> pessoas = new List<Pessoa>
108+
{
109+
new Pessoa { Nome = "Ana", Idade = 25 },
110+
new Pessoa { Nome = "João", Idade = 30 },
111+
new Pessoa { Nome = "Maria", Idade = 22 },
112+
new Pessoa { Nome = "Pedro", Idade = 35 }
113+
};
114+
115+
var pessoasFiltradas = pessoas
116+
.Where(p => p.Idade > 25)
117+
.OrderBy(p => p.Nome);
118+
119+
Console.WriteLine("Pessoas com mais de 25 anos:");
120+
121+
foreach (var pessoa in pessoasFiltradas)
122+
{
123+
Console.WriteLine($"{pessoa.Nome}, {pessoa.Idade} anos");
124+
}
125+
}
126+
}
127+
```
128+
129+
## 5. Conclusão
130+
131+
Neste artigo, introduzimos o LINQ e as expressões lambda, mostrando como essas ferramentas podem facilitar a manipulação de dados em C#. Com a prática, você poderá aplicar esses conceitos em seus projetos, tornando seu código mais limpo e eficiente.
132+
133+
No próximo artigo, continuaremos a explorar mais recursos do C# e como utilizá-los em aplicações do mundo real. Até lá, bons estudos e mãos à obra!
134+
135+
---
136+
137+
**Referências:**
138+
139+
- Documentação oficial do [LINQ](https://learn.microsoft.com/en-us/dotnet/csharp/programming-guide/concepts/linq/)
140+
- Exemplos de [Expressões Lambda](https://learn.microsoft.com/en-us/dotnet/csharp/programming-guide/statements-expressions-operators/lambda-expressions)

0 commit comments

Comments
 (0)