Loading s5obj_lang_labo_1...
dotnet new console -o ImageLib
subl .
class Program { static void Main() { Console.WriteLine("Hello World!"); } }
dotnet run
dotnet build
class ThisIsAClass { private int thisIsAnAttribute;
public int ThisIsAProperty { get; }
public void ThisIsAMethod(string thisIsAParameter) { float thisIsAVariable = 3.14f; } }
| Couleur | R | G | B |
|---|---|---|---|
| Noir | 0 | 0 | 0 |
| Blanc | 1 | 1 | 1 |
| Rouge | 1 | 0 | 0 |
| Vert | 0 | 1 | 0 |
| Bleu | 0 | 0 | 1 |
struct Color { public float r; public float g; public float b; }
Color c;
c.r = 1.0f; c.g = 0.0f; c.b = 0.0f;
Console.WriteLine($"{c.r} {c.g} {c.b}");
// commentaire sur une seule ligne
/* commentaire sur plusieurs lignes */
public override string ToString() { return $"({r} {g} {b})"; }
public float Gray() { return 0.299f * r + 0.587f * g + 0.114f * b; }
Console.WriteLine($"Grayscale value: {c.Gray()}");
c.r = 5.0f;
struct Color { private float r; private float g; private float b; }
public Color(float r, float g, float b) { this.r = r; this.g = g; this.b = b; }
Color c = new Color(1.0f, 0.0f, 0.0f);
Color c = new Color(5.0f, 0.0f, 0.0f); Console.WriteLine(c);
public Color(float r, float g, float b) { if (r < 0) r = 0f; if (r > 1) r = 1f; if (g < 0) g = 0f; if (g > 1) g = 1f; if (b < 0) b = 0f; if (b > 1) b = 1f; this.r = r; this.g = g; this.b = b; }
public float GetR() { return r; } public float GetG() { return g; } public float GetB() { return b; }
Console.WriteLine($"R={c.GetR()} G={c.GetG()} B={c.GetB()}");
public float R { get => r; set { r = Math.Clamp(value, 0f, 1f); } }
public float G { get => g; set { g = Math.Clamp(value, 0f, 1f); } }
public float B { get => b; set { b = Math.Clamp(value, 0f, 1f); } }
public float Gray { get { return 0.299f * r + 0.587f * g + 0.114f * b; } }
Color g = color.Gray;
Color c1 = c; Console.WriteLine($"c={c} c1={c1}");
c.SetR(0.5f); Console.WriteLine($"after modification of c :"); Console.WriteLine($"c={c} c1={c1}");
Program.TestValueSemantics(c); Math.Clamp(value, 0f, 1f); Console.WriteLine("Hello World!");
static void TestValueSemantics(Color c) { Console.WriteLine("~~~~~~ in TestValueSemantics() ~~~~~~"); Console.WriteLine($"c={c}");
c.SetR(0.8f);
Console.WriteLine($"after modification : c={c}"); }
Program.TestValueSemantics(c);
Console.WriteLine("~~~~~~ after TestValueSemantics() ~~~~~~"); Console.WriteLine($"c={c}");
static void TestValueSemantics(ref Color c) { ... }
TestValueSemantics(ref c);
class Program { static void TestValueSemantics(Color c) { Console.WriteLine("~~~~~~ in function TestValueSemantics() ~~~~~~"); Console.WriteLine($"c={c}"); c.SetR(0.8f); Console.WriteLine($"after modification of c : c={c}"); }
static void TestColor() { Color c = new Color(1.0f, 0.0f, 0.0f);
/* First test Color c.r = 1.0f; c.g = 0.0f; c.b = 0.0f; Console.WriteLine($"{c.r} {c.g} {c.b}"); */ Console.WriteLine(c);
// Test getter and setter Console.WriteLine($"R={c.GetR()} G={c.GetG()} B={c.GetB()}"); c.SetB(1.0f); Console.WriteLine($"B={c.GetB()}");
// Test on value semantics Color c1 = c; Console.WriteLine($"c={c} c1={c1}"); c.SetR(0.5f); Console.WriteLine($"~~~~~~ after modification of c : c={c} c1={c1}");
Program.TestValueSemantics(c); Console.WriteLine("~~~~~~ after function TestValueSemantics() ~~~~~~"); Console.WriteLine($"c={c} c1={c1}"); }
static void Main() { // test struct Color TestColor(); } }
public struct Color { private float r; private float g; private float b;
public Color(float r, float g, float b) { if (r < 0) r = 0f; if (r > 1) r = 1f; if (g < 0) g = 0f; if (g > 1) g = 1f; if (b < 0) b = 0f; if (b > 1) b = 1f; this.r = r; this.g = g; this.b = b; }
public float GetR() { return r; } public float GetG() { return g; } public float GetB() { return b; }
public void SetR(float r) { this.r = Math.Clamp(r, 0f, 1f); } public void SetG(float g) { this.g = Math.Clamp(g, 0f, 1f); } public void SetB(float b) { this.b = Math.Clamp(b, 0f, 1f); }
public float Gray() { return (0.299f * r + 0.587f * g + 0.114f * b); }
public override string ToString() { return $"{r} {g} {b}"; } }