मुख्य सामग्री पर जाएँ
Skillpedia
सामान्य कोडिंग48k · #5889

csharp

यह क्या करती है

यह गाइड C# कोड को ज़्यादा कुशल और साफ़ तरीके से लिखना सिखाती है, और भाषा के best practices का पालन करती है। इसमें कोड के हिस्सों को बेहतर बनाने के उदाहरण हैं, ताकि कोड पढ़ने और maintain करने में आसान हो।

कब इस्तेमाल करें

  • ✓जब आप C# में programming सीख रहे हों।
  • ✓जब आप मौजूदा C# कोड की समीक्षा या सुधार कर रहे हों।
  • ✓जब आप ज़्यादा modern और सुरक्षित C# कोड लिखना चाहते हों।

Skill का लिंक

https://github.com/sickn33/agentic-awesome-skills/blob/main/plugins/agentic-awesome-skills-claude/skills/super-code/csharp/SKILL.md

इसे कॉपी करके अपने AI (Claude, ChatGPT या Cursor) में पेस्ट करें और निर्देशों का पालन करने को कहें।

कैसे इस्तेमाल करें

सबसे आसान तरीका: मैसेज कॉपी करके अपने AI में पेस्ट करें। वह skill पढ़कर निर्देशों का पालन करेगा।

पेस्ट करने के लिए तैयार मैसेज

इस skill से मेरी मदद करो: https://github.com/sickn33/agentic-awesome-skills/blob/main/plugins/agentic-awesome-skills-claude/skills/super-code/csharp/SKILL.md इस लिंक की SKILL.md फ़ाइल पढ़ो और मेरे काम में उसके निर्देशों का पालन करो।
क्या आप चाहते हैं कि आपका AI ऐसी skills खुद ढूँढे?मुफ़्त Skillpedia MCP इंस्टॉल करें: बस एक लाइन, और हर काम से पहले यह 15,000+ skills में खोजता है।1 मिनट में इंस्टॉल करें →

AI से क्या माँगें: उदाहरण

“लिस्ट (list) संभालने के लिए मैं C# में साफ़ कोड कैसे लिख सकता हूँ?”

हर हफ़्ते 5 नई skills, 1 मिनट में पढ़ें।

यह कैसे काम करती है

गाइड C# में काम करने के पुराने और नए तरीकों की तुलना करती है। यह code examples को साथ-साथ दिखाती है, फर्क बताती है और समझाती है कि एक तरीका दूसरे से बेहतर क्यों है।

तकनीकी सामग्री (मूल SKILL.md)

लेखक का मूल टेक्स्ट, अंग्रेज़ी में, सीधे GitHub से।

C#: Idiomatic Efficiency Reference

When to Use

  • Use this skill when the task matches this description: Language-specific super-code guidelines for csharp.

Table of Contents

  1. LINQ & Collections
  2. Null Handling
  3. Async/Await
  4. Records & Pattern Matching
  5. Error Handling
  6. Resource Management
  7. Anti-patterns specific to C#

1. LINQ & Collections {#linq}

// ❌ Imperative accumulation
var result = new List<string>();
foreach (var item in items) {
    if (item.IsActive) result.Add(item.Name.ToUpper());
}

// ✅
var result = items
    .Where(i => i.IsActive)
    .Select(i => i.Name.ToUpper())
    .ToList();
// ❌ Manual grouping
var grouped = new Dictionary<string, List<Item>>();
foreach (var item in items) {
    if (!grouped.ContainsKey(item.Category))
        grouped[item.Category] = new List<Item>();
    grouped[item.Category].Add(item);
}

// ✅
var grouped = items.GroupBy(i => i.Category)
    .ToDictionary(g => g.Key, g => g.ToList());
// ❌ Checking Any() then First()
if (items.Any(i => i.IsValid)) {
    var first = items.First(i => i.IsValid);
}

// ✅
var first = items.FirstOrDefault(i => i.IsValid);
if (first is not null) { ... }

Prefer method syntax for chains of 2+ operations. Query syntax is fine for complex joins.


2. Null Handling {#nulls}

// ❌ Nested null checks
string city = null;
if (user != null && user.Address != null) {
    city = user.Address.City;
}

// ✅
var city = user?.Address?.City;
// ❌ Ternary for null fallback
var name = user != null ? user.Name : "Unknown";

// ✅
var name = user?.Name ?? "Unknown";
// ❌ Null check before event invocation
if (OnChanged != null) OnChanged(this, args);

// ✅
OnChanged?.Invoke(this, args);
// ❌ Throwing ArgumentNullException manually
if (name == null) throw new ArgumentNullException(nameof(name));

// ✅ (C# 10+)
ArgumentNullException.ThrowIfNull(name);

Enable nullable reference types (<Nullable>enable</Nullable>) project-wide.


3. Async/Await {#async}

// ❌ Blocking on async code
var result = GetDataAsync().Result; // deadlock risk

// ✅
var result = await GetDataAsync();
// ❌ async void (exceptions are unobservable)
async void OnButtonClick() { await DoWork(); }

// ✅ — async Task; only async void for event handlers that truly require it
async Task OnButtonClick() { await DoWork(); }
// ❌ Sequential awaits for independent work
var a = await FetchA();
var b = await FetchB();

// ✅
var (a, b) = (await Task.WhenAll(FetchA(), FetchB())) switch
{
    var r => (r[0], r[1])
};
// or cleaner with ValueTuple:
var taskA = FetchA();
var taskB = FetchB();
var a = await taskA;
var b = await taskB;
// ❌ Wrapping synchronous code in Task.Run inside a library
public Task<int> GetValue() => Task.Run(() => ComputeSync());

// ✅ — let the caller decide; expose sync method
public int GetValue() => ComputeSync();

Add ConfigureAwait(false) in library code. Omit in app/UI code.


4. Records & Pattern Matching {#records}

// ❌ Manual equality, ToString, Deconstruct for data types
class Point {
    public int X { get; init; }
    public int Y { get; init; }
    // + Equals, GetHashCode, ToString...
}

// ✅ (C# 9+)
record Point(int X, int Y);
// ❌ if-else chain for type checking
if (shape is Circle) {
    var c = (Circle)shape;
    return c.Radius * c.Radius * Math.PI;
} else if (shape is Rectangle) { ... }

// ✅
return shape switch {
    Circle { Radius: var r } => r * r * Math.PI,
    Rectangle { Width: var w, Height: var h } => w * h,
    _ => throw new ArgumentException($"Unknown shape: {shape}")
};
// ❌ Range checking with && 
if (score >= 0 && score <= 100) { ... }

// ✅ (C# 9+)
if (score is >= 0 and <= 100) { ... }

5. Error Handling {#errors}

// ❌ Catching Exception to log and swallow
try { Process(); }
catch (Exception ex) { logger.LogError(ex, "error"); }

// ✅ — catch specific, rethrow if you can't handle
try { Process(); }
catch (HttpRequestException ex) {
    throw new ServiceException("upstream failure", ex);
}
// ❌ throw ex (resets stack trace)
catch (Exception ex) { throw ex; }

// ✅
catch (Exception ex) { throw; } // preserves stack trace
// or wrap: throw new AppException("context", ex);

…
अक्सर पूछे जाने वाले सवाल

LINQ क्या है?

LINQ (Language Integrated Query) एक तरीका है जिससे C# भाषा के अंदर ही data collections को query और manipulate किया जा सकता है, जिससे कोड छोटा और साफ़ बनता है।

'Async/Await' का मतलब क्या है?

Async/Await ऐसे keywords हैं जो background में चलने वाले काम वाला कोड लिखने में मदद करते हैं, बिना main program को रोके। इससे program का response तेज़ रहता है।

C# में 'Records' क्या हैं?

Records C# में class का एक खास प्रकार हैं, जो ऐसे data-focused types बनाना आसान करते हैं जिन्हें बदला नहीं जा सकता (immutable)। इनमें अपने आप equality check और string representation जैसी सुविधाएँ होती हैं।

जानकारी

लेखक का मूल विवरण

Language-specific super-code guidelines for csharp.

repo: sickn33/agentic-awesome-skills

लोकप्रियता

GitHub स्टार
48k
रैंकिंग में स्थान
#5889
लाइसेंस
MIT
अपडेट की गई
15/10/2026

क्या यह skill काम की है?

0

लॉग इन करें वोट करने के लिए।

कमेंट

  • …

इस repository की और skills

00-andruia-consultant

48k

आपके एजेंट को AI प्रोजेक्ट शुरू करने या उन्हें बेहतर बनाने में मदद करता है। यह code का विश्लेषण करता है, tools सुझाता है और स्पेनिश भाषा में action plan बनाता है।

AI और एजेंटएजेंट

007

48k

आपका एजेंट security audit और threat modeling करता है। यह प्रोजेक्ट को हमलों और कमजोरियों से बचाने में काम आता है।

कोडिंगसिक्योरिटी

10-andruia-skill-smith

48k

आपके एजेंट को AI tools बनाने या उन्हें बेहतर करने में मदद करता है। यह तय करता है कि tools कैसे काम करेंगे, documentation लिखता है और structure की जांच करता है।

AI और एजेंटएजेंट

20-andruia-niche-intelligence

48k

आपका एजेंट किसी खास industry का summary बनाता है। भरोसेमंद स्रोतों की मदद से यह प्रोजेक्ट का संदर्भ, नियम, इस्तेमाल के तरीके और जोखिम समझने में मदद करता है।

लेखन और डॉक्यूमेंटरिसर्च

मिलती-जुलती skills