2014-02-25 39 views
0

如何從C#中的單個消息佈局創建多個記錄?假設我有一條消息叫做MSG1,它包含5個字段FLD1-FLD5。其中FLD4和FLD5需要對消息的每次出現都是唯一的。現在我想賺10,000或100萬美元,那麼我最好的辦法是什麼?使用C#從單個消息佈局創建多個記錄

例子:

**MSG1** 
FLD1: 20140227 
FLD2: ABCD 
FLD3: BUICK 
FLD4: ID0000000001 
FLD5: REG0000000001 
+0

FLD4和FLD5應該基於其他字段的內容是唯一的還是唯一的ID? – Mattis

+0

什麼是C#消息佈局? –

回答

0

我已經編寫這個非常簡單地根據你的解釋。以下代碼可能會爲您提供起點。

namespace GenerateMillionTags 
{ 
class Program 
{ 
    static void Main(string[] args) 
    { 
     var list = Message1.CreateMessages(10000); 

     // Do whatever you want with the list. 
    } 
} 

public class Message1 
{ 
    public string fld1_ { get; set; } 
    public string fld2_ { get; set; } 
    public string fld3_ { get; set; } 
    public string fld4_ { get; set; } 
    public string fld5_ { get; set; } 

    public Message1() 
    { 
     fld1_ = @"20140227"; 
     fld2_ = @"ABCD"; 
     fld3_ = @"BUICK"; 
    } 

    public Message1(string fld1, string fld2, string fld3) 
    { 
     fld1_ = fld1; 
     fld2_ = fld2; 
     fld3_ = fld3; 
    } 

    public static List<Message1> CreateMessages(uint count) 
    { 
     var messageList = new List<Message1>(); 
     for (int i = 0; i < count; i++) 
     { 
      // here ids can be made/formatted as sophisticately as you want. 
      messageList.Add(new Message1() {fld4_ = "ID" + i, fld5_ = "REG" + i}); 
     } 

     return messageList; 
    } 
} 
} 
+1

是的,這是正確的。但我試圖回答這個問題。問題看起來很簡單,我們可以創建複雜的解決方案和結構作爲解決方案,但您的問題似乎並沒有要求它。 –

+0

我不認爲你瞭解我的意見 – EricSchaefer

+0

這是可能的。 –

相關問題