-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #105 from marcode24/2024-02-cs
🔧 Add Visual Studio solution file
- Loading branch information
Showing
4 changed files
with
139 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
class FuncionesAlcance | ||
{ | ||
// Variable global | ||
static int globalVariable = 10; | ||
|
||
public static void Execute() | ||
{ | ||
// 1. Función sin parámetros ni retorno | ||
PrintHello(); | ||
|
||
// 2. Función con un parámetro | ||
PrintMessage("Hello, C#!"); | ||
|
||
// 3. Función con varios parámetros | ||
AddNumbers(5, 10); | ||
|
||
// 4. Función con retorno | ||
int result = MultiplyNumbers(3, 4); | ||
Console.WriteLine($"Resultado de la multiplicación: {result}"); | ||
|
||
// 5. Funciones dentro de funciones (con función local) | ||
OuterFunction(); | ||
|
||
// 6. Variables locales y globales | ||
int localVariable = 5; | ||
Console.WriteLine($"Variable local: {localVariable}"); | ||
Console.WriteLine($"Variable global antes de modificar: {globalVariable}"); | ||
ModifyGlobalVariable(); | ||
Console.WriteLine($"Variable global después de modificar: {globalVariable}"); | ||
|
||
// 7. Función con dos cadenas de texto y retorno de un número (Dificultad Extra) | ||
int count = PrintNumbersWithText("Fizz", "Buzz"); | ||
Console.WriteLine($"El número de veces que se imprimió un número es: {count}"); | ||
} | ||
|
||
// Función sin parámetros ni retorno | ||
public static void PrintHello() | ||
{ | ||
Console.WriteLine("Hello, World!"); | ||
} | ||
|
||
// Función con un parámetro | ||
public static void PrintMessage(string message) | ||
{ | ||
Console.WriteLine(message); | ||
} | ||
|
||
// Función con varios parámetros | ||
public static void AddNumbers(int a, int b) | ||
{ | ||
Console.WriteLine($"Suma: {a + b}"); | ||
} | ||
|
||
// Función con retorno | ||
public static int MultiplyNumbers(int a, int b) | ||
{ | ||
return a * b; | ||
} | ||
|
||
// Función externa con función interna (local) | ||
public static void OuterFunction() | ||
{ | ||
// Función local dentro de una función | ||
static void InnerFunction() | ||
{ | ||
Console.WriteLine("Soy una función interna."); | ||
} | ||
|
||
Console.WriteLine("Soy la función externa."); | ||
InnerFunction(); // Llamada a la función interna | ||
} | ||
|
||
// Modificar la variable global | ||
public static void ModifyGlobalVariable() | ||
{ | ||
globalVariable += 10; | ||
} | ||
|
||
// Función que recibe dos cadenas de texto y retorna un número (Dificultad Extra) | ||
public static int PrintNumbersWithText(string text1, string text2) | ||
{ | ||
int count = 0; | ||
|
||
for (int i = 1; i <= 100; i++) | ||
{ | ||
if (i % 3 == 0 && i % 5 == 0) | ||
{ | ||
// Si es múltiplo de 3 y 5, imprime ambas cadenas concatenadas | ||
Console.WriteLine(text1 + text2); | ||
} | ||
else if (i % 3 == 0) | ||
{ | ||
// Si es múltiplo de 3, imprime la primera cadena | ||
Console.WriteLine(text1); | ||
} | ||
else if (i % 5 == 0) | ||
{ | ||
// Si es múltiplo de 5, imprime la segunda cadena | ||
Console.WriteLine(text2); | ||
} | ||
else | ||
{ | ||
// Imprime el número y aumenta el contador | ||
Console.WriteLine(i); | ||
count++; | ||
} | ||
} | ||
|
||
// Retorna la cantidad de veces que se imprimió un número | ||
return count; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# Visual Studio Version 17 | ||
VisualStudioVersion = 17.5.002.0 | ||
MinimumVisualStudioVersion = 10.0.40219.1 | ||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "weekly-challenges", "weekly-challenges.csproj", "{9AC8FB7D-179A-4836-81E5-618E5173EB35}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Release|Any CPU = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{9AC8FB7D-179A-4836-81E5-618E5173EB35}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{9AC8FB7D-179A-4836-81E5-618E5173EB35}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{9AC8FB7D-179A-4836-81E5-618E5173EB35}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{9AC8FB7D-179A-4836-81E5-618E5173EB35}.Release|Any CPU.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
GlobalSection(ExtensibilityGlobals) = postSolution | ||
SolutionGuid = {AD2B30D3-5AA5-4748-A39E-CCFC40A3CD2C} | ||
EndGlobalSection | ||
EndGlobal |